Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of self-starting and scheduled tasks of Python script under Linux

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "Python script self-start and timed task example analysis under Linux", the content is simple and easy to understand, organized clearly, I hope to help you solve doubts, let Xiaobian lead you to study and learn "Python script self-start and timed task example analysis under Linux" this article bar.

First, let Python run automatically with Linux boot

Prepare the script auto.py to start

Edit the following files with root privileges

sudo vim /ect/rc.local

Edit the command for the startup script above 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 logs.

Second, let Python script start regularly

Prepare the timed startup script auto.py

Edit the following files with root privileges

sudo vim /etc/crontab

Add the following command at the end of the file

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

The above code means to execute the script and print the log every two minutes.

III. crontab preparation explanation

basic format

* * * * * user command Time sharing day month week user command

IV. Examples

1. Perform once every minute

* * * * * user command

2. Perform once every 2 hours

* */2 * * * user command (/indicates frequency)

3. Perform once a day at 8:30

30 8 * * * user command

4. Once every 30 and 50 minutes

30,50 * * * user command (, indicates juxtaposition)

4. Perform once at 8:30 from the 3rd to the 6th of each month

30 8 3-6 * * user command (-indicates range)

5. Perform once every Monday at 8:30

30 8 * * 1 user command (week range 0- 7, 0 and 7 represent Sunday) The above is "Python script self-startup and timed task example analysis under Linux" All the contents of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report