PDA

View Full Version : Cron Job


dawho9
Sep 22, 2002, 11:55 PM
OK, simple question I hope. I have a very important program to run each day, a perl script for my counter-strike stats. :-)

I was figuring I could just do a cron job, but have no clue how to do it.

I downloaded a couple of programs from versiontracker that I was hoping would help, but I would always get an error telling me that the program does not exist.

You see, I am trying to run the file stats.pl. They syntac according to the webpage is to run it as:

nice ./stats.pl -v

Thanks,

dw9

drmbb2
Sep 24, 2002, 08:26 AM
In /usr/bin there is a program called "crontab" which makes submitting a cron job very easy. Create a simple text file (say "my_cronjobs.cron") in the format:


minutes hours day(of month) month day command

For example

0 2 * * * nice ./stats.pl -v

would run your script every day at 2:00AM (you must use a 24hr clock)

45 13 * * mon nice ./stats.pl -v

would run your script every Monday at 1:45PM

To submit your script as a cron job, just type the command

"crontab my_cronjobs.cron"

Note that any time you shutdown or reboot the machine, you would have to resubmit your crontab script, but as long as the machine is running, your script will be run as scheduled. Oh, adn there is a man page for crontab as well.

Cheers, Michael

Camelot
Sep 24, 2002, 11:50 PM
Originally posted by drmbb2:
In /usr/bin there is a program called "crontab" which makes submitting a cron job very easy. Create a simple text file (say "my_cronjobs.cron") in the format:

minutes hours day(of month) month day command

For example

0 2 * * * nice ./stats.pl -v

would run your script every day at 2:00AM (you must use a 24hr clock)

45 13 * * mon nice ./stats.pl -v

would run your script every Monday at 1:45PM

To submit your script as a cron job, just type the command

"crontab my_cronjobs.cron"

Note that any time you shutdown or reboot the machine, you would have to resubmit your crontab script, but as long as the machine is running, your script will be run as scheduled. Oh, adn there is a man page for crontab as well.

Cheers, Michael

Of course, you could just run crontab -e and add the line your your regular crontab file, meaning it would be persistent across rebooted.

Oh, and the command probably doesn't run because the system doesn't know where it is.

If you run "nice ./stats.pl", it's going to run from the current directory, which is undefined.

You're much better off specifying the full pathname of the script:

nice /path/to/stats.pl -v

VEGAN
Sep 25, 2002, 07:27 AM
cron runs the daily, weekly, monthly scripts, but where are these cron jobs recorded? I tried to list with `sudo crontab -l' but it says no jobs.

drmbb2
Sep 25, 2002, 10:12 AM
The periodic scripts themselves are in /etc/periodic, the crontab entries are in the file /etc/crontab, and the cron and crontab processes are called by the rc initialization files at startup (usually rc.d on Linux systems, but I'm not sure which specific startup file(s) does this in OS X). Note that crontab only works with user files, not the system crontab entries - those must be edited directly by the ROOT user.

VEGAN
Sep 25, 2002, 10:26 AM
Originally posted by drmbb2:
The periodic scripts themselves are in /etc/periodic, the crontab entries are in the file /etc/crontab, and the cron and crontab processes are called by the rc initialization files at startup (usually rc.d on Linux systems, but I'm not sure which specific startup file(s) does this in OS X). Note that crontab only works with user files, not the system crontab entries - those must be edited directly by the ROOT user.

OK, I ask another question as you appear to be a person who might know.

I was trying to play with `at' and never got it work. I created 'at.deny' and 'at.allow' (added my user to the latter) but it doesn't work... what am I missing?

The `at' job is listed but never executed... it just waits there... time passes and nothing...

drmbb2
Sep 25, 2002, 11:30 AM
Are you being sure to specify a time? (you don't need one for "-batch" jobs, but you do for "at").

for example: "at filename now wednesday" would execute immediately (if you use the time "now" you must specify a date)

or, "at filename 13:22" would execute at 1:22PM today

VEGAN
Sep 25, 2002, 11:57 AM
Originally posted by drmbb2:
Are you being sure to specify a time? (you don't need one for "-batch" jobs, but you do for "at").

for example: "at filename now wednesday" would execute immediately (if you use the time "now" you must specify a date)

or, "at filename 13:22" would execute at 1:22PM today

No, I didn't forget the time:
`at now + 3 min'