Cron Jobs

From SlackWiki
Revision as of 03:38, 2 June 2009 by Erik (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Well you are reading this tutorial because you need to schedule a certain task or a script on a certain day. First you need to know a few things about cron before we get started. One of those things is the table below:

1 = minute past the hour (0 through 59)
2 = hour (0 through 23)
3 = day of month (1 through 31)
4 = month of year (1 through 12)
5 = day of the week
    0 = Sunday (This can also be 7)
    1 = Monday
    2 = Tuesday
    3 = Wednesday
    4 = Thursday
    5 = Friday
    6 = Saturday

This table will be used later on in this tutorial. Now first part of editing a cron entry is typing in the following command:

crontab -e

(I usually do this as root if the command needed to run requires root)

Well this brings up the regular vi(elvis in slackware) screen. Most people don't use VI. There is a variable you can set to change the default cron editor.

export VISUAL=pico

That will change the default editor for the session to pico. It's a little friendlier when it comes to editing for some people out there. There is also a GNU editor like pico called nano. Now we need to schedule a command for running.

6 10 * * * /root/scripts/example

The example above here will run the command /root/scripts/example at 10:06 every day. The numbers above (on the table) symbolize the mark of where it belongs. So the 6 would be number 1 on the table and the 10 will be the hour.

*/30 * * * * /root/scripts/example

The entry above will run the /root/scripts/example every 30 minutes of every day. Now save your entries and they will run when you tell them to. You also want to add 1> /dev/null on the end of your command so you send the output to /dev/null instead of roots email (this is default on slackware). Good luck!