This is a website by Willem van Zyl

I'm a project manager, software developer, Apple evangelist and geek from South Africa. I'm passionate about web and mobile application development, usability, productivity, physics, astronomy, science fiction and fantasy.

If you would like to contact me, message me on Twitter or send me an email.

How to define user crontabs (scheduled tasks) on Mac OS X and Linux

22 Feb 2009

Unix systems' cron service runs scheduled tasks at dates and times defined by users in crontab files. A user can check their crontab entries from the command line by entering:

crontab -l

... or check another user's crontab by entering:

sudo crontab -u {username} -l

Crontab entries are defined as follows:

{minute (*-0-59)} {hour (*-0-23)} {monthday (*-1-31)}
  {month (*-1-12)} {weekday (*-0-7)} {path} {script}

For example, to execute a script on the hour on Mondays, you would use:

0 * * * 1 /usr/bin/php5 the_script.php

To override crontab settings, edit a crontab with either one of these commands:

crontab -e

sudo crontab -u {username} -e

... or create a text file containing cron entries:

0,30 *   * * *   /usr/bin/php5 /home/willem/something.php
0    23  * * 0,3 sh /home/willem/cronscripts/run_backup.sh
0    */2 * * *   /usr/bin/php5 /var/www/geekology/sitemap.php

If you created a text file, load it to your or another user's crontab by entering:

crontab {path_to_text_file}

sudo crontab -u {username} {path_to_text_file}
Do you like this? Share it:

Copyright © Geekology 2011. All Rights Reserved.

Hosted by Code. Like. Clockwork.