Crontab Linux timed Run program

Source: Internet
Author: User

The first is the script execution, but error: in the crontab operation, the results found no results, view the/var/log/message log, found that crontab has executed, but failed.
Manual operation is possible, put in crontab inside found can not run.
Processing method: Do not use relative path in the script, all change to absolute path

The second is to edit the/var/spool/cron/user user to execute the username, typically root
If the change does not work, reload cron:
Treatment method:/etc/init.d/cron Reload

The third type is edited with sudo crontab-e
Use the following command add entries to crontab should take effect right away.
#crontab-E

If not yet, from its service:
Treatment method:/etc/init.d/crond Restart

Format of crontab:
1th column min 1~59
2nd Hour 1~23 (0 = midnight)
3rd Liege 1~31
4th Column Month 1~12
5th Column Week 0~6 (0 = Sunday)
6th List of commands to run

Time-sharing day and month command to run
*/5 * * * * bash/opt/tools/**.sh >/tmp/***.log 2>&1

Here are some examples of crontab file entries:

* * * * */usr/local/apache/bin/apachectl restart
The above example shows that 21:30 restarts Apache per night.

4 1,10,22 * */usr/local/apache/bin/apachectl restart
The above example shows that 4:45 restarts Apache on the 1, 10, and 22nd of the month.

1 * * 6,0/usr/local/apache/bin/apachectl restart
The above example shows that 1:10 restarts Apache every Saturday and Sunday.

0,30 18-23 * * */usr/local/apache/bin/apachectl restart
The above example shows that Apache restarts every 30 minutes from 18:00 to 23:00 every day.

0 * * 6/usr/local/apache/bin/apachectl restart
The above example shows the restart of Apache every Saturday at 11:00am.

* */1 * * * */usr/local/apache/bin/apachectl restart
Restart Apache every hour

* 23-7/1 * * * */usr/local/apache/bin/apachectl restart
From 11 o'clock to 7 in the morning, restart Apache every hour.

0 4 * Mon-wed/usr/local/apache/bin/apachectl restart
4th per month with 11-point restart from Monday to Wednesday Apache

0 4 1 Jan */usr/local/apache/bin/apachectl restart
4-point restart of Apache on January 1

Crontab Linux timed Run program

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.