Here is a typical crontab entry and the definition of cron fields:
00 03 * * * /tmp/zing.sh
- minute (00-59)
- hour (00-23)
- day of the month (01-31)
- month of the year (01-12)
- day of the week (0-6 with 0=Sunday)
- program or command to run
Ranges (X-Y) and steps (X-Y/Z) can also be defined.
Special @reboot option
Recent versions of cron support @reboot instead of time and day settings to run a command after boot. For example:
@reboot /usr/bin/command-to-run
I am not sure if I like this option, compared to using system start up scripts, like /etc/rc.d/rc.local.
User crontabs (including the root user)
To edit a user crontab (including root):
crontab -e
To delete a crontab:
crontab -r
User crontabs are stored as text files in /var/spool/cron/.
System crontab
The system crontab is stored in /etc/crontab. It can be changed (as root) with a text editor.
The system crontab has one extra field before the program to run, which is the user to run the command as (usually root).
Thanks for sharing the article. You can find more examples about crontab at crontab command examples in unix
ReplyDeletevijay,
ReplyDeleteI always have to reference something when I am doing something odd, like day of the month jobs, etc.
Bonus tip, when cron jobs start, they don't get a full shell environment so you can't rely on the $PATH being there. For that reason, it is always a good idea to put the full path to all programs and files in the command, or if you are running a script, set the environment variables in the script.
Keith