![]() var/spool/cron/ or /var/cron/tabs/ is directory for personal user crontab files. All individual user must must use crontab command to install and edit their jobs as described above. Usually only used by root user or daemons to configure system wide jobs. Make a backup everyday: /path/to/backup/script.sh More about /etc/crontab file and /etc/cron.d/* directories Run ntpdate command every hour: /path/to/ntpdate Special once, at once a year, “0 0 1 1 as once a month, “0 0 1 * once a week, “0 0 * * once a day, “0 0 * * as once an hour, “0 * * * *”. It will not just save your time but it will improve readability. Instead of the first five fields, you can use any one of eight special strings. # crontab -r -u username Use special string to save time To remove or erase all crontab jobs use the following command: See “ Disable The Mail Alert By Crontab Command” for more information. To mail output to particular email account let us say you need to define MAILTO variable as follows: 3 * * * /root/backup.sh >/dev/null 2>&1 For example: 0 3 * * * /root/backup.sh >/dev/null 2>&1 To stop receiving email output from crontab you need to append >/dev/null 2>&1. Steps are also permitted after an asterisk, so if you want to say every two hours, just use */2.īy default the output of a command or a script (if any produced), will be email to your local email account. ![]() The separator (/) : This operator specifies a step value, for example: “0-23/” can be used in the hours field to specify command execution every other hour.The dash ( -) : This operator specifies a range of values, for example: “5-15” days, which is equivalent to typing “5,6,7,8,9,….,13,14,15” using the comma operator.The comma ( ,) : This operator specifies a list of values, for example: “1,5,10,15,20, 25”.For example, an asterisk in the hour time field would be equivalent to every hour or an asterisk in the month field would be equivalent to every month. The asterisk ( *) : This operator specifies all possible values for a field.Want to run Unix command say /path/to/unixcommand at 5 after 4 every Sunday? enter: 5 4 * * sun /path/to/unixcommand How do I use operators?Īn operator allows you to specifying multiple values in a field. In this example, I am running /scripts/phpscript.php at 10 pm on weekdays, enter: 0 22 * * 1-5 /scripts/phpscript.phpĮxecute /root/scripts/perl/ at 23 minutes after midnight, 2am, 4am …, everyday, enter: 23 0-23/2 * * * /root/scripts/perl/ Let us run /path/to/script.sh at 2:15pm on the first of every month, enter: 15 14 1 * * /path/to/script.sh ![]() To run /path/to/command five minutes after midnight, every day, enter: 5 0 * * * /path/to/command First, install your cronjob by running the following command:Īppend the following entry: 0 3 * * * /root/backup.sh If you wished to have a script named /root/backup.sh run every day at 3am, your crontab entry would look like as follows. Your cron job looks as follows for system jobs:ġ 2 3 4 5 USERNAME /path/to/command arg1 arg2
0 Comments
Leave a Reply. |