Detailed steps for Python script self-start and scheduled start under Linux

Detailed steps for Python script self-start and scheduled start under Linux

1. Python automatically runs at startup

Suppose the Python self-starting script is auto.py Then edit the following files with root privileges:

sudo vim /etc/rc.local

If you don't have rc.local please read this article

Edit the command to start the script above exit 0

/usr/bin/python3 /home/selfcs/auto.py > /home/selfcs/auto.log

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

2. Start the Python script regularly

Edit the following file with root privileges

sudo vim /etc/crontab 

Add the following command at the end of the file

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

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

3. Crontab Writing Explanation

Basic format

* * * * * user command
Time-sharing, daily, monthly and weekly user commands

3.1 Example 1: Execute once every minute

* * * * * user command

2. Execute every 2 hours

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

3. Execute once every day at 8:30

30 8 * * * user command

4. Execute once at 30 and 50 minutes of every hour

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

5. Execute once at 8:30 on the 3rd to 6th of each month

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

6. Execute once every Monday at 8:30

30 8 * * 1 user command (the range of the weekday is 0-7, 0 and 7 represent Sunday)

Summarize

The above is the detailed steps for the self-start and scheduled startup of Python scripts under Linux introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • Detailed method of packaging Python3 program under Windows and Linux
  • Python modifies the permissions of files (folders) in Linux
  • Detailed tutorial on installing Python 3.8.1 on Linux
  • Tutorial on upgrading and installing python 3.8 and configuring pip and yum under Linux
  • Two ways to install Python3 on Linux servers
  • Python logs in to Linux through SSH and implements operations
  • Detailed explanation of the process of deleting the built-in version of Python in Linux

<<:  How to use a field in one table to update a field in another table in MySQL

>>:  JS implements a simple brick-breaking pinball game

Recommend

DIV background semi-transparent text non-translucent style

DIV background is semi-transparent, but the words ...

How to create components in React

Table of contents Preface Component Introduction ...

An example of implementing a simple finger click animation with CSS3 Animation

This article mainly introduces an example of impl...

Vue.js Textbox with Dropdown component

A Textbox with Dropdown allows users to select an...

MySQL 8.0.13 installation and configuration tutorial under CentOS7.3

1. Basic Environment 1. Operating system: CentOS ...

How to enable MySQL remote connection in Linux server

Preface Learn MySQL to reorganize previous non-MK...

The latest virtual machine VMware 14 installation tutorial

First, I will give you the VMware 14 activation c...

Understanding and using callback functions in JavaScript

Table of contents Overview What are callbacks or ...

Analysis of the method of setting up scheduled tasks in mysql

This article uses an example to describe how to s...

About uniApp editor WeChat sliding problem

The uniapp applet will have a similar drop-down p...

What are the new features of Apache Spark 2.4, which will be released in 2018?

This article is from the Apache Spark Meetup held...

Vue realizes picture switching effect

This article example shares the specific code of ...