PDA

View Full Version : Any way to have a script run at a specific time of day?




debo
Apr 7, 2004, 07:51 PM
How can I have a script in unix execute at a certain time during the day?



switcheroo
Apr 7, 2004, 08:42 PM
you can do it the same way osx runs its maintainence tasks as well as most other unicies by using the cron daemon. add an entry to the file /etc/crontab you can use the existing entries as examples and find out more in 'man 5 crontab'

debo
Apr 7, 2004, 08:59 PM
Is there any other way? This is just something I need to run like 5 times tommorrow as a project, and didn't want to have to be next to the computer each time. Then I won't be running it again after tomorrow.

switcheroo
Apr 7, 2004, 09:40 PM
yep there is. but you still need to mess with cron!! use the 'at' command. It is disabled in mac osx so you need to enable it by removing the comment symbol # in /etc/crontab
making
#*/5 * * * * root /usr/libexec/atrun
into:
*/5 * * * * root /usr/libexec/atrun

then to use the at command --

to run at a certain time today use:
echo 'open file.txt' | at 10:40 pm

or at a time tomorrow:
echo 'open file.txt' | at 10:40 am tomorrow

or at a certain date and time:
echo 'open file.txt' | at 10:40 am 4/8/04

or even at teatime!
echo 'open file.txt' | at teatime

try it out a few times times within a few minutes to make sure your syntax is correct

if your script doesn't need arguments use
at -f script 11:00 pm

to see the at job queue use atq

siliconjones
Apr 7, 2004, 10:32 PM
Go to versiontracker and download cronnix. It is a GUI for cron. Very useful.

-- cronnix at versiontracker -- (http://www.versiontracker.com/dyn/moreinfo/macosx/9478)