L i n u x 之 c r o n t a b

1. Introduction to Crontab

       The function of the crontab command is to schedule the execution of some commands at certain time intervals.     

 

       In LINUX, the tasks executed periodically are generally handled by the cron daemon [ps -ef|grep cron].

       cron reads one or more configuration files that contain the command line and when it was invoked.
       The cron configuration file is short for "crontab" and "cron table".

       

 

Second, Crontab uses

     Command format: crontab [-u user] file / crontab [-u user] [ -e | -l | -r ]

    Use the command crontab -e to edit the crontab and add the required scheduled tasks in it. The user's timed task file is /var/spool/cron/username, and the crontab -e command will be equivalent to vim /var/spool/cron/username.

  The format description is as follows:

In each of the above fields, the following special characters can also be used:

Asterisk (*): represents all possible values. For example, if the month field is an asterisk, it means that the command operation will be executed every month after the constraints of other fields are met.

 

Comma (,): A list range can be specified with comma-separated values, for example, "1,2,5,7,8,9"

 

Middle bar (-): You can use a middle bar between integers to represent a range of integers, for example "2-6" means "2,3,4,5,6"

 

Forward slash (/): You can specify the interval frequency of time with a forward slash, for example "0-23/2" means to execute every two hours. At the same time, forward slashes can be used together with asterisks, such as */10, if used in the minute field, it means to execute every ten minutes.

 

Three, examples

It is executed once every minute, and the log is stored in /tmp/test.log.

*/1 * * * * /app/cos_nas/test.sh 1>>/tmp/test.log 2>>/tmp/test.log

 

Execute the command at 5, 15, 25, 35, 45, and 55 minutes at 4:00, 5:00, and 6:00 every day. 

5,15,25,35,45,55 16,17,18 * * * command

 

Every Monday, Wednesday, and Friday at 3:00 pm, the system enters the maintenance state and restarts the system.

00 15 * * 1,3,5 shutdown -r +5

 

Execute the command innd/bbslin in the user directory at 10 minutes and 40 minutes of every hour: 

10,40 * * * * innd / bbslink 

 

 

Reference: https://www.cnblogs.com/intval/p/5763929.html

         https://www.cnblogs.com/longjshz/p/5779215.html

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326138946&siteId=291194637