Linux Python script bootstrap and timing task detail

  • 2020-06-12 11:40:02
  • OfStack

preface

Colleagues recently asked about Python 1 since the launch of the script with the task of timing problem, find a lot of friends on the are not very familiar with, so this paper is to introduce about Linux Python script since the launch of the relevant content and timing task, share out for your reference learning, few words said, to 1 look at the details:

1. Let Python run automatically with Linux startup

Have the script auto.py ready to start

Edit the following files with root permissions


sudo vim /ect/rc.local

Edit the command for the startup script on exit 0


/usr/bin/python3.5 /home/edgar/auto.py > /home/edgar/auto.log

Finally, restart Linux and the script will run automatically and print the log.

2. Let the Python script start on time

Have the script auto.py ready for regular startup

Edit the following files with root permissions


sudo vim /etc/crontab

Add the following command to the end of the file


2 * * * * root /usr/bin/python3.5 /home/edgar/auto.py > /home/edgar/auto.log

The above code means that the script is executed every two minutes and the log is printed.

3. crontab

The basic format


* * * * * user command
 points   when   day   month   weeks   The user   The command 

4. Give examples

1. Execute once per minute


* * * * * user command

2. Perform every 2 hours


* */2 * * * user command (/ According to the frequency )

3. It will be executed once at 8:30 every day


30 8 * * * user command

4. Once for 30 and 50 minutes per hour


30,50 * * * * user command ( , Juxtaposition) 

4. It will be executed once every month from the 3rd to the 6th at 8:30


30 8 3-6 * * user command  ( - Range) 

5. It will be executed once every Monday at 8:30


/usr/bin/python3.5 /home/edgar/auto.py > /home/edgar/auto.log
0

conclusion


Related articles: