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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script Executing Itself? 1

Status
Not open for further replies.

BenRussell

Programmer
Mar 12, 2001
243
0
0
US
I want to make a script, for instance, that executes itself every week at 12:00PM GMT, and executes a subroutine called &UpdateForm (for instance). How would I get this script to run at this exact time every week, without anyone having to access the script, it just executing itself? - Ben Russell
- President of Intracor Technologies (
 
Hi,

If you're running under Unix/Linux, use crontab to execute your script at specific intervals - 'man crontab' should give you the info you need.

There is similar scheduling software under Windows but I don't think it's that reliable.

Finally, you may not be able to specify which subroutine to call so you might have to write a specific script that performs the functions of &UpdateForm.

Bye for now,

Tim --
Tim <tim@planetedge.co.uk>
 
If your admin has installed it, just type 'crontab' :)

Create an empty file called 'mycron' although it can be called anything. Inside the file you need to put some crontab configuration commands like the following:

* * * * * /home/user/blah.sh

Will run blah.sh every minute, on the minute, every day.

I wouldn't suggest doing that tho =)

A more practical example would be:

59 23 * * * /home/user/blah.sh

Which executes blah.sh at 11:59pm every day.

Here's what the *'s mean:

First * - Minute (0-59)
Second * - Hour (0-23)
Third * - Day of month (1-31)
Fourth * - Month of year (1-12)
Fifth * - Day of week (0-6, 0 = sunday)

Also, you must specify a complete path to your script. Simply putting * * * * * blah.sh will not be enough if blah.sh is somewhere different to where crontab is.

Now you're ready to start the cronjob. At the prompt type:

crontab mycron

That's it. To list current jobs type crontab -l.

To edit the cronjob once it's been set, type crontab -e which will launch the default editor, vi, emacs etc.

You can have multiple cronjobs in the one file for running different scripts at different times.

Also, the good thing about crontab is that if your script fails it will email the administrator detailing the error so you know as soon as there's a problem.

Hope this helps,

Tim --
Tim <tim@planetedge.co.uk>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top