Search This Blog

Thursday, January 29, 2009

Scheduling in linux using the crontab

When you need to do something i.e mail, run a script, backup etc. automatically after some specific time, i.e once a day. once a week, after every hour.
crontab command is helpful for such.

crontab -e Edit your crontab file, or create one if it doesn't already exist.
crontab -l Display your crontab file.
crontab -r Remove your crontab file.
crontab -v Display the last time you edited your crontab file. (This option is only available on a few systems.)

* * * * * command to be executed
- - - - -
| | | | |
| | | | +----- day of week (0 - 6) (Sunday=0)
| | | +------- month (1 - 12)
| | +--------- day of month (1 - 31)
| +----------- hour (0 - 23)
+------------- min (0 - 59)

# min(0-59)    hours(0-23)   day(1-31)   month(1-12)    dow(0-6)   command
34 2 * * * sh /root/backup.sh

min hour day month dyaofweek
e.g
55 23 * * * sh /etc/sipx_mapp/cdrscript.sh
50 23 * * * do something
01 * * * * do something [ or every hour]
Means every day at 23:55 (11:55 at night) script will run

14 2 29 8 5 ./skynet
This will launch at 2:14 AM, on August 29 if it is a Friday.

Activation parameters:
@reboot = run at boot and reboot only
@yearly = run at midnight Jan 1 each year (equiv to 0 0 1 1 *)
@annually = run at midnight Jan 1 each year (equiv to 0 0 1 1 *)
@monthly = run at midnight on the first day of each month (equiv to 0 0 1 * *)
@weekly = run at midnight each Sunday (equiv to 0 0 * * 0)
@daily = run at midnight each day (equiv to 0 0 * * *)
@ midnight = run at midnight each day (equiv to 0 0 * * *)
@ hourly = run on the first second of every hour (equiv to 0 * * * *)

1 comment:

  1. Please Describe this command with proper Example.

    ReplyDelete