Adding Linux shell (.sh) script and add the regular tasks

First, add sheel script

1, first create an executive program: vim a.sh

2, editor: #! / bin / the bash 
        to python3 python.py test2.log >> 2> &. 1

3, add the permission: chmod + x ./a.sh  

4, view the execution results: ./a.sh

Second, add regular tasks

Installation: apt-get install cron (default will be installed server environment)

1, crontab -e: Modify crontab file if the file does not exist will be created automatically. 

2, crontab -l: Display a crontab file. 

3, crontab -r: remove crontab files.

4, crontab -ir: crontab files before deleting alert the user.

6, cron file syntax:

      Minute hour day month week command

       0-59 0-23 1-31 1-12 0-6 command (range, 0 represents a line generally corresponding to a task on Sunday)

        "*" Representatives within the range of numbers,

          "/" Stands for "every"

          "-" represents the numbers from one to a certain number,

          "" Several separate discrete digital

7, / sbin / service crond start // Start Service

   / Sbin / service crond stop // shut down service

   / Sbin / service crond restart // restart the service

   / Sbin / service crond reload // reload the configuration

14 Super practical examples of the use of Crontab

1. 02:00 daily tasks

  0 2 * * * /bin/sh backup.sh

5:00 and 17:00 2. day mission

  0 5,17 * * * /scripts/script.sh

3. Perform the task once per minute

  * * * * * /scripts/script.sh

4. Every Sunday 17:00 mission

  0 17 * * sun /scripts/script.sh

5. Each 10min perform a task

  */10 * * * * /scripts/monitor.sh

6. perform tasks in particular a few months

  * * * jan,may,aug * /script/script.sh

7. In particular certain days of the mission

  0 17 * * sun,fri /script/scripy.sh

  Every Friday, Sunday 17:00 to perform tasks

8. perform tasks in the first Sunday of a month

  0 2 * * sun [ $(date +%d) -le 07 ] && /script/script.sh

9. every four hours to perform a task

  0 */4 * * * /scripts/script.sh

10. Monday, Sunday mission

  0 4,17 * * sun,mon /scripts/script.sh

11. Each 30 seconds to perform a task

  We have no direct way to perform a similar example of Appeal, since the minimum is 1min. However, we can adopt the following method.

  1.  * * * * * /scripts/script.sh 

  2.  * * * * * sleep 30; /scripts/script.sh 

Arranged in a plurality of tasks 12. The command

  * * * * * /scripts/script.sh; /scripts/scrit2.sh

13. perform tasks once a year

  @yearly /scripts/script.sh

  @yearly like "0011 *." It will be performed within the first minute of each year, usually we can use this to send New Year's greetings.

14. The system performs reboot

  @reboot /scripts/script.sh

Guess you like

Origin www.cnblogs.com/wu-wu/p/11214503.html