The linuxcrontab command regularly restarts apache and mysql

Source: Internet
Author: User
The apache and mysql services are automatically restarted on a regular basis without restarting the server. The procedure is as follows: 1. Restart apache and mysql services on a regular basis at and every day without restarting the server. The procedure is as follows:
I. Restart apache and mysql services at and every day
[Root @ www bin] # Cd/Opt/
[Root @ www opt] # vim reboot.txt
Enter the following content in the reboot.txt.txt file and save it.
0 12 *** service HttpdRestart
0 12 *** service mysqld restart
0 16 *** service httpd restart
0 16 *** service mysqld restart
2. Add the new file to the cron service.
[Root @ www opt] # CrontabReboot.txt
[Root @ www opt] # crontab-l
0 12 *** service httpd restart
0 12 *** service mysqld restart
0 16 *** service httpd restart
0 16 *** service mysqld restart
Iii. Restart the cron Service
[Root @ www opt] #/sbin/service crond restart
Note:
Cron is a linux scheduled execution tool that can run jobs without human intervention. Since Cron is a built-in service in Linux, but it does not automatically get up, you can use the following methods to start and close this service:
/Sbin/service crond start // start the service
/Sbin/service crond stop // close the service
/Sbin/service crond restart // restart the service
/Sbin/service crond reload // reload the configuration
Basic time table format:
* *** Program
Minutes, days, months, and weeks Command
The 1st column indicates minute 1 ~ 59. Each minute is represented by * or */1.
The first column indicates the hour 1 ~ 23 (0 indicates 0 points)
The 3rd column indicates the date 1 ~ 31
The 4th column indicates the month 1 ~ 12
The Identification Number of column 5th is from day of the week to day ~ 6 (0 indicates Sunday)
6th columns of commands to run
When Column 1st is set to *, the program is executed every minute. When Column 2nd is set to *, the program is executed every hour, and so on.
When Column 1st is a-B, it indicates that execution is performed from the minute a to the minute B. If Column 2nd is a-B, it indicates that execution is performed from the hour a to the hour B, other analogy
When Column 1st is */n, it indicates execution is performed every n minutes. If Column 2nd is */n, it indicates execution is performed every n hours.
When Column 1st is a, B, c ,... a, B, c ,... execute in minutes. The 2nd columns are a, B, c ,... a, B, c... execute in hours, and so on
Some examples of crontab files:
30 21 ***/usr/local/etc/rc. d/lighttpd restart
The above example indicates restarting lighttpd at every night.
45 4, 10, 22 **/usr/local/etc/rc. d/lighttpd restart
The preceding example indicates that the lighttpd is restarted at on the 1st, 10th, and 22th of each month.
10 1 ** 6, 0/usr/local/etc/rc. d/lighttpd restart
The preceding example indicates restarting lighttpd at every Saturday and Sunday.
0, 30 18-23 ***/usr/local/etc/rc. d/lighttpd restart
The preceding example indicates restarting lighttpd every 30 minutes between and every day.
0 23 ** 6/usr/local/etc/rc. d/lighttpd restart
The preceding example indicates restarting lighttpd at every Saturday.
**/1 ***/usr/local/etc/rc. d/lighttpd restart
Restart lighttpd every hour
* 23-7/1 ***/usr/local/etc/rc. d/lighttpd restart
Restart lighttpd every hour between PM and PM.
0 11 4 * mon-w Ed/Usr/local/etc/rc. d/lighttpd restart
Restart lighttpd from every Monday to Wednesday on the 4th of each month.
0 4 1 jan */usr/local/etc/rc. d/lighttpd restart
Restart lighttpd at on January 1, January 1.
Related Article

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.