How to write python self-startup and timed startup scripts in Linux
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.