How to Use crontab for regular tasks
[Precondition]
OS: RedHat fedora 2
[Brief introduction]
CronIs a daemon task to allow others tasks to be automatically run at the regular interval. cron then wakes up every minute, and examining all crontab files stored, and checking each command to see whether it shocould be run in the current minute. when executing commands, any output is mailed to the owner of the crontab or the user named in the mailto environment variable in the crontab, if such exists.
CrontabMaintains crontab files for individual users, so we can useCrontabCommand to edit/remove/list crontab files.
[Crontab commands]
Crontab-e edit crontab file, or create one if it doesn't already exist.
Crontab-l display your crontab file.
Crontab-r remove your crontab file.
Crontab-u the user of crontab, if no-u option, it means to use current login user.
[Format of crontab file]
* *** Command to be executed
|
| + ----- Day of week (0-7) (Sunday = 0/7)
| + ------- Month (1-12)
| + --------- Day of month (1-31)
| + ----------- Hour (0-23)
+ ------------- Minute (0-59)
* In the value field above means all legal values as in braces for that column. the value column can have a * or a list of elements separated by commas. an element is either a number in the ranges shown above or two numbers in the range separated by a hyphen (meaning an inclusive range ).
For example:
*/2 ***** echo 'append me'>/tmp/tmp.txt
It means that 'append me' will be appended into/tmp/tmp.txt every minute. '2' is step, and it can be used front five time elements.
*/2 1, 3, 5 * echo 'append me'>/tmp/tmp.txt
Only at 1th, 3th, 5th hour will append 'append me' into/tmp/tmp.txt every minute.
In words, we can use shell scripts to do something and add running commands into cron daemon to do at the background. So crontab-e shoshould be used directly.
[How to start/stop/restart cron]
# Service crond start/stop/restart