Use crontab for VPS automation on Linux vps/servers

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, CentOS installed under the crontab

Yum Install Vixie-cron crontabs//Installation crontab

Chkconfig Crond on//set to boot from
Service Crond Start//Startup

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 to perform task List crontab-l2, 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
Explain: Minutes Hours Date Monthly payment Week Command
Range: 0-59 0~23 1~31 1~12 0~7,0 and 7 both represent Sunday

In the crontab we will often use the *,-/n These 4 symbols, OK or again draw a table, more clear:

Symbol Explain
* (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 a split-open multiple value. such as: 9 1,16,20 * * Command every month 1, 16, 20th, 9:30 execute command.
-(minus) Represents a time frame. such as 0 9-17 * * * checkmail every day 9 o'clock to 17 points on the hour to execute the checkmail command
/n Represents a long time every n. 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

Use crontab for VPS automation on Linux vps/servers

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.