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

How to write python self-startup and timed startup scripts in Linux

2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article "how to write python self-startup and timed startup scripts in Linux" article most people do not understand, so Xiaobian summarized the following content for everyone, detailed content, clear steps, with certain reference value, I hope you can read this article to gain something, let's take a look at this article "how to write python self-startup and timed startup scripts in Linux" article.

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 startup script commands above exit 0

/usr/bin/python3``.5 ``/home/edgar/auto``.py > ``/home/edgar/auto``.log Finally restart Linux, the script will automatically run and print the log.

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 to 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 ``command2, executed every 2 hours

* *``/2` `* * * user ``command` `(/indicates frequency)3. Execute once a day at 8:30

30 8 * * * user ``command4, executed once every 30 and 50 minutes

30,50 * * * * user ``command``(, indicates juxtaposition) 4. Execute once at 8:30 from the 3rd to the 6th of each month

30 8 3-6 * * user ``command` `(-indicates range) 5. Executed once every Monday at 8:30

30 8 * * 1 user ``command` `(week range is 0-7,0 and 7 represent Sunday) The above is about "how to write python self-startup and timed startup scripts in Linux" The content of this article, I believe everyone has a certain understanding, I hope the content shared by Xiaobian is helpful to everyone, if you want to know more related knowledge content, please 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

Development

Wechat

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

12
Report