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 does ubuntu execute python scripts regularly?

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces ubuntu how to regularly execute python script related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this ubuntu how to regularly implement python script article will have a harvest, let's take a look at it.

Crontab

Edit scheduled tasks

Crontab-e

Parameter definition:

-u specifies the user,-- l lists the user task schedule

-r Delete user tasks

-e Editing user tasks

English introduction:

# edit this file to introduce tasks to be run by cron.

#

# each task to run has to be defined through a single line

# indicating with different fields when the task will be run

# and what command to run for the task

#

# to define the time you can provide concrete values for

# minute (m), hour (h), day of month (dom), month (mon)

# and day of week (dow) or use'*'in these fields (for 'any'). #

# notice that tasks will be started based on the cron's system

# daemon's notion of time and timezones.

#

# output of the crontab jobs (including errors) is sent through

# email to the user the crontab file belongs to (unless redirected).

#

# for example, you can run a backup of all your user accounts

# at 5 a.m every week with:

# 0 5 * * 1 tar-zcf / var/backups/home.tgz / home/

Chinese explanation:

Format

M h dom mon dow command

The above are abbreviations. Full spelling comparison is provided here:

Minute (m), hour (h), day of month (dom), month (mon), day of week (dow)

The meaning is as follows:

M on the minute of each hour to perform the task

H the number of hours of each day to perform the task

Dom performs this task on the day of each month.

In what month of each year does mon perform this task?

On the day of the week on which dow performs this task-command specifies the program to be executed

Order for hours, days, months and weeks

0-59 0-23 1-31 1-120-6 command

Other:

Where 0 in the middle of the week means Sunday.

* represents any time, such as the first minute, using * represents every minute of every hour

-represents an interval, such as 1-3

If the interval is not contiguous, you can use it, for example, wq save and exit after editing

Restart the service

Service cron restart

Matters needing attention

Note that the absolute path must be used. Otherwise, the execution may fail.

For example, we have to implement

Python bwh.py

So the first thing you need to do is

Which python

To see the real path of the python command

Root@ubuntu:~# which python/root/.pyenv/shims/python

Then, check the full path of bwh.py, under the folder where bwh.py is located.

Pwd/app/python/blog

Then the path is

/ app/python/blog/bwh.py

So the whole record should be edited like this.

0 9 * / root/.pyenv/shims/python / app/python/blog/bwh.py > / tmp/new_blog_bwh.log

The above record refers to the execution of / root/.pyenv/shims/python / app/python/blog/bwh.py at 9: 00 sharp every day and the output of the printed log to / tmp/new_blog_bwh.log

This is the end of the article on "how ubuntu executes python scripts regularly". Thank you for reading! I believe you all have a certain understanding of "how ubuntu executes python scripts regularly". If you want to learn more, you are welcome to follow 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

Internet Technology

Wechat

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

12
Report