Web Hosting Talk







View Full Version : How-to Cronjobs


CR-
01-31-2004, 05:05 AM
Getting Started with Crontab...
Type crontab -e as the user that you want the Cron Job to be executed as.
The format of the job is like this. I'm gonna use some varibles, you should remember
those from algebra, for those of you that don't it is a letter that represents another
value (usually a number).

a b c d e f

where...
a = The minute after the hour that you want it done
b = The hour you want it done (Military Time)
c = Day of the Month
d = Month of the Year
e = Day of the week
f = 'command'

5 0 * * * /usr/local/bin/email
Like the above example, /usr/local/bin/email, will run every night at 12:05 AM.
The * means to run every instance of the value in the field. Like a asterisk in the day field means to run everyday

Other Useful crontab commands
crontab -e opens the editor
crontab -l lists the contents of the crontab
crontab -r removes the crontab

My friend created this, so I can't take the credit, but hopefully someone finds it useful.

J.

hookgr
12-31-2004, 08:35 PM
something missing maybe ???
dont see any use of the vars...

xnor84
07-04-2007, 04:35 PM
edit /var/spool/cron/username

pico -w /var/spool/cron/username

add this line

4 3 * * * /usr/bin/updatedb

don't forget to restart crond

service crond restart

this will make updatedb runs at 03:04 am every day :egflag:

BigGorilla
07-05-2007, 10:24 AM
edit /var/spool/cron/username

pico -w /var/spool/cron/username

[...]

don't forget to restart crond


crontab -u user -e (or simply just crontab -e if editing your own crontab) is the more appropriate way to edit crontab files as the changes will take affect without requiring a manual restart of crond, and you don't have to be root to edit your own file (since you'd have to be root to restart crond).

The above commands are for Linux. Other *nix will have similar options, just do a man crontab.

supraj
07-13-2007, 06:03 AM
Always check crontab if you suspect your server is hacked. list the crontab and check what command it executes. Most hacked servers have suspecious cronjobs