Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can we set a script to be executed everyday at 9am?

Status
Not open for further replies.

NKnina

Programmer
Oct 3, 2001
7
US
Hi,
I need to create a timer to generate report on daily basis. I want the shell script to be executed at 9am everyday. How do we create a timer for this, where a countdown is set for 24 hrs and when it's time, the shell script will be executed. After the execution, timer will be restarted and ticking for the next 24 hrs. Pls assist with the timer shell script...

Thanks and Regards,
NINA
 
You can just set up cron to run the script at 9am everyday. If you don't know cron just check out the man pages, it's pretty simple.
 
You need to set up a cron job to call your script.

Set your EDITOR variable

$ EDITOR=vi; export EDITOR

then edit your crontab file

$ crontab -e

and add a line pointing to your script.

* 9 * * * /path/script.sh

The first 5 parameters refer to minutes, hours, day of month, month, day of week. A star means every minute or every day.

Save the crontab and wait until 9 am.

Note that the cron job won't read your environment when it runs, so you need to use full paths etc in your script.

For more info read the crontab man page.


Steve
 
err Steve, don't you mean

0 9 * * * /path/script.sh Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Thanks guys for the tips.

So, first thing i should do is to create a crontab file containing * 9 * * * /path/script.sh
and save it in the same folder as the script to be executed. Pls correct me if i'm wrong. I'll also check the details of crontab in the man page. Well, thanks again..

Regards,
NINA
 
I don't think you've quite got the gist:

The easiest way to edit a crontab file is to issue the command:

crontab -e

This should then bring up your crontab file (it might be better if you set your EDITOR variable to vi (EDITOR=vi;export EDITOR) before you issue the crontab -e command, as editing crontabs using ED is somewhat tiresome.

You can then insert your line. As Mike suggests above, it would probably be better to amend your command so that the first * is replaced by 0. This would ensure that your hjobs runs only at 9:00 am, rather than every minute between 9:00 and 9:59! Hope this helps. If you don't currently have a crontab and cron complains, you may have to add your username in /var/adm/cron/cron.allow first. Cheers.
 
You could also create an "at" job.

create a file called maybe 9am_everyday.sh
or whatever you want. Then point it to the file you want to run everyday at a certain time. The file you create should look something like below:

/usr/bin/sh /home/beaster/final_run/stripit_ftpit.sh
echo "/usr/bin/sh /home/beaster/final_run/ftpit_run.sh" | at 9am tomorrow

This will run you file at 9am and put the file back on the que for tommorrow. You can check the "at" job using at -l and if it needs to be killed, just at -r and the job id number.


Hope this helps,
Beaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top