Use of cron for scheduled tasks in Ubuntu

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.