1. For some Ubuntu versions of crontab, cron is installed and started by default. If not, set and start (chkconfig \ sysv-rc-conf ). Configuration file/etc/crontab: # mhdommondowusercommand17 ***** rootcd/& amp ;&
1. About crontab
In some Ubuntu versions, cron is installed and started by default. If not, set and start (chkconfig \ sysv-rc-conf ). Configuration file/etc/crontab:
# M h dom mon dow user command
17 * root cd/& run-parts -- report/etc/cron. hourly
25 6 * root test-x/usr/sbin/anacron | (cd/& run-parts -- report/etc/cron. daily)
47 6 ** 7 root test-x/usr/sbin/anacron | (cd/& run-parts -- report/etc/cron. weekly)
52 6 1 ** root test-x/usr/sbin/anacron | (cd/& run-parts -- report/etc/cron. monthly)
Ubuntu calls the run-parts command to regularly run all scripts under four directories.
The scripts in/etc/cron. hourly are run once every hour and 17 hours.
The script in/etc/cron. daily runs once a day at 06:25 every day.
The scripts in/etc/cron. weekly run once a week at 06:47 on the first day of each week.
The script in/etc/cron. monthly runs once a month at 06:52 on the first day of each month.
The preceding execution time can be modified by yourself.
Ii. shell scripts
You only need to put the script to the corresponding directory. Note the following:
1.The script file name cannot contain the "." symbol. You can write "im-alarm", but not "im-alarm.sh ". (Failed execution due to naming issues)
2. "#!" must be added at the beginning of the script. /Bin/bash ", otherwise the run-parts call fails.
Otherwise, running run-parts will cause the following error:
Run-parts: failed to exec/etc/cron. hourly/backup-website: Exec format error
Run-parts:/etc/cron. hourly/backup-website exited with return code 1
Iii. Start and Stop
Start, stop, and restart cron in ubuntu
Sudo/etc/init. d/cron start
Sudo/etc/init. d/cron stop
Sudo/etc/init. d/cron restart
Check whether cron is running:
Pgrep cron