Operating System - HP-UX
1825764 Members
2004 Online
109687 Solutions
New Discussion

Re: Scheduling jobs using at command

 
PM Srividhya
Advisor

Scheduling jobs using at command

Hi all,

I have a list of scripts to be run on batch and I have a menu to start/stop them.

For e.g. On executing the menu_script, it displayes as following:
******************************
List of batches

1. script 1
2. script 2
3. script 3
.
.
10. stop batch jobs

99. exit
Enter option:
***********************************

On entering the option I want to put the script in the scheduler(run the script at some time interval - . ./script | at "now + 30 minutes").
This makes the script to run after 30 minutes, but it is not repating again.
I will be passing arguments from the menu_script to script1 and so I cannot give
echo ". $0" | at "" as the last statement in the script1 (as mentioned in the man page!)

How do I repeat run the script using at command? I don't want to use crontab.

Thanks,
Vidhya.

P.S. This time I'll be very generous in giving points ;O)
12 REPLIES 12
Peter Godron
Honored Contributor

Re: Scheduling jobs using at command

Hi,
you could include in your script1/script2.. files the at command, which would then trigger the repeat run.

Problem is, if the system is shut down, you will lose your at jobs, that is why cron was invented.

Dennis Handly
Acclaimed Contributor

Re: Scheduling jobs using at command

>so I cannot give echo ". $0" | at "" as the last statement in the script1 (as mentioned in the man page!)
>How do I repeat run the script using at command?

If you can't edit the script, you can't repeat them. That is where you need to add the "at now + 30".

I suppose you could pass a parm -r ## to your script that tells it to optionally reschedule itself using at(1).
SANTOSH S. MHASKAR
Trusted Contributor

Re: Scheduling jobs using at command

Hi,

How do u want to repeat it?

After certain interval OR after finishing running instance of script?

-Santosh
PM Srividhya
Advisor

Re: Scheduling jobs using at command

I want to repeat it after regular intervals.
Pete Randall
Outstanding Contributor

Re: Scheduling jobs using at command

As Peter tried to explain, you need to put something like this in your script:

echo "/script1" | at now + 30 minutes

That way, every time the script is run, it tells at to do it again in 30 minutes.


Pete

Pete
SANTOSH S. MHASKAR
Trusted Contributor

Re: Scheduling jobs using at command

Hi,

U can do like this,


create a file say JOB_PARAM

Enter following to it.
---------------------------
#! /usr/bin/ksh
JOB_REPEAT=TRUE

# Repeat interval in seconds
REPEAT_INTERVAL=1800 # 30 mins
--------------------------------

At the beginning of ur script add following
-------------------------------------------
. /JOB_PARAM

while [ JOB_REPEAT="TRUE" ]
do
at -f
sleep REPEAT_INTERVAL
done
-----------------------------------------


Thats all.


If u want to stop the job set


JOB_REPEAT=FALSE in JOB_PARAM

If u want to change repeat interval
change REPEAT_INTERVAL value in JOB_PARAM.


-Santosh
Yogeeraj_1
Honored Contributor

Re: Scheduling jobs using at command

hi,

below a quote from "man at" which clear explains how to achieve this:

Add a command to the file named weekly-run in directory jobs in the home directory so that it automatically reschedules itself every time it runs. This example reschedules itself every Thursday at 1900 (7:00 p.m.):

echo "sh $HOME/jobs/weekly-run" | at 1900 thursday next week


hope this helps!

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Dennis Handly
Acclaimed Contributor

Re: Scheduling jobs using at command

>echo "sh $HOME/jobs/weekly-run" | at ...

I assume the reason for the silly echo instead of doing "at -f file", is to allow changes to the file between "now" and that future date?
PM Srividhya
Advisor

Re: Scheduling jobs using at command

I think I have mentioned that I have to pass some arguments to the script from the calling script and so I cannot use it the way mentioned in the man page.

**I will be passing arguments from the menu_script to script1 and so I cannot give
echo ". $0" | at "" as the last statement in the script1 (as mentioned in the man page!)**
SANTOSH S. MHASKAR
Trusted Contributor

Re: Scheduling jobs using at command

U can write in while loop as

sh |at now +
in place of
at -f

try this


-Santosh
Dennis Handly
Acclaimed Contributor

Re: Scheduling jobs using at command

>**I will be passing arguments from the menu_script to script1 and so I cannot give
echo ". $0" | at "" as the last statement in the script1 (as mentioned in the man page!)**

Can you or can't you edit script1?? Passing args to script1 has nothing to do with editing it.
Dennis Handly
Acclaimed Contributor

Re: Scheduling jobs using at command

You can of course have script1 pass its current parms back to itself when it invokes at(1).