Linux vps/Server using crontab to implement the VPS Automation tutorial

Source: Internet
Author: User
Tags fpm vps

VPS or server often need VPS or server often need to regularly backup data, scheduled to restart a service or scheduled execution of a program and so on, generally in Linux use crontab,windows below is the use of scheduled tasks (win is the graphical interface setup is relatively simple), The following mainly describes the installation and use of crontab on Linux vps/servers.

The crontab is a common timing execution tool under a unix/linux system that can run a specified job without human intervention.

First, the installation of crontab

1. Install crontab under CentOS

Yum Install Vixie-cron crontabs//Installation crontab

Chkconfig Crond on//set to boot from service Crond start//start

Description: The Vixie-cron package is the main program for Cron, and the Crontabs package is the program used to install, uninstall, or enumerate the tables used to drive the cron daemon.

2. Install crontab under Debian

Apt-get Install cron//In most cases Debian is installed.

/etc/init.d/cron Restart//Restart Crontab

Second, crontab use method

1. View crontab scheduled execution Task list

Crontab-l 2, add crontab scheduled to perform tasks

CRONTAB-E the crontab Task command may be entered differently because of the crontab default editor.

As shown in the Nano editor, the use of simple, directly at the end of the file by the crontab command format input can, ctrl+x exit, and then lose y return to save.

Another is the VI editor, first press the I key, at the end of the file Press crontab command format input, and then press ESC, and then enter: Wq enter.

3. crontab Task Command writing format

Format: Minute hour dayofmonth month DayOfWeek command explanation: Minute hour date monthly pay week order range: 0-59 0~23 1~31 1~12 0~7,0 and 7 both represent Sunday in crontab we will Always use *,-/n These 4 symbols, OK or draw another form, clearer:

The symbol Interpretation * (asterisk) represents all valid values. such as: 0 * * * Backup executes the backup command at 23 o'clock, regardless of the day of the week. , (comma) represents the splitting of multiple values. such as: 9 1,16,20 * * Command every month 1, 16, 20th, 9:30 execute command. -(minus sign) represents a time range. such as 0 9-17 * * * checkmail every day from 9 o'clock to 17 points on the hour of execution Checkmail command/n stands for every n long time. such as */5 * * * * check command is performed every 5 minutes, as with 0-59/5. Here are some examples to deepen your understanding:

Perform a backup program 3:00 every day: 0 3 * * */root/backup.sh

Log cleanup Program every Sunday 8:30:8 * * 7/root/clear.sh

1 weeks 5 0 o'clock Full execution test program: 0 0 * * 1,5 test

Every May 12 14 o'clock executes Wenchuan program: 0 5 */root/wenchuan

Restart every 15 minutes from 18 o'clock in the evening to 23 PHP-FPM:*/15 18-23 * * */ETC/INIT.D/PHP-FPM

Linux vps/Server using crontab to implement the VPS Automation tutorial

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.