Operating System - Linux
1753656 Members
5728 Online
108798 Solutions
New Discussion юеВ

Re: scheduling a shell script

 
SOLVED
Go to solution
Shivkumar
Super Advisor

Re: scheduling a shell script

Hi James,

I had scheduled the job home/sksonkar/shiv.sh|at 0200 tomorrow

it exexuted successfully today morning.

I believe it will not execute continuously tomorrow and day after.

For making it to run continuoulsy do i need to put the at command in the script shiv.sh and run "shiv.sh &" or run with the command "nohup shiv.sh" as a background process ?

Is there a command to view the details of the jobs scheduled via at command ?

Thanks,
Shiv
James R. Ferguson
Acclaimed Contributor

Re: scheduling a shell script

Hello Shiv:

No, the script will not automatically execute again as setup.

One crude way to make continuous execution happen, as already noted, would be to place the body of your script's instructions in a loop that once executed, sleeps for 86,400 seconds. The drawback, of course, is that if your script ever fails, it's done until you manually intervene.

Another way to cause successive runs would be to use 'at' as you have, and add, as the *last* instruction for your script to re-schedule itself:

# at -f /home/sksonkar/shiv.sh now + 1 days

See the manpages for 'at' for more options!

Lastly, if you want to run a task with regularity, you should 'cron' it. This is what 'cron' is designed to do. You can run a process every day, many times a day, only on selected days of the week, etc. etc.

Please consult the 'crontab' manpages. For example, to run your script every 24-hours you would create a crontab entry (using the user account you want to use) like:

30 2 * * * /home/sksonkar/shiv.sh

This would run your script every day at 02:30

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: scheduling a shell script

Hi (again) Shiv:

Oh, I forgot to answer your last question.

To see tasks (if any) that have been scheduled via 'at', login as the user that scheduled them and do:

# at -l

To remove one, use:

# at -r

...with the job-id seen in 'at -l'. For instance:

# at -l
job 1138035079.a at Mon Jan 23 11:51:19 2006
# at -r 1138035079.a

Since you will ask, (good!) I'll tell you ahead of time that the jobid, here "1138035079" is the Unix epoch time --- the number of seconds since January 1, 1970. The jobid of 'at' is "translated" in the output. That is, "1138035079" is your localtime as shown: Mon Jan 23 11:51:19 2006.

Regards!

...JRF...