当前位置:网站首页>Programming skills: script scheduling
Programming skills: script scheduling
2022-06-27 14:47:00 【ysds20211402】
from : Micro reading https://www.weidianyuedu.com
Script scheduling It's very common in several minute work , such as Some core data bosses want to see every day , If you come every morning to sort out the data and send it , It's too inefficient . The right thing to do is to write python Script , Schedule it regularly every day , Automatically send email daily report to the boss . And such as The amount of table data in a database is too large , To improve query efficiency , You can write an intermediate table , Insert filtered data at regular intervals every morning , In the future, you only need to find the intermediate table with a small amount of data . All in all , Script scheduling is important , Learning is . Summarize two scheduling methods :1、Linxu crontab Dispatch .2、windows Task scheduler
Linxu crontab Dispatch
There are some prerequisites for using this scheduling method :
1、 Need to know some common linxu sentence
2、 You need a server
Linxu crontab Scheduling syntax
crontab The composition of the command is time + action , There are time-sharing days, months and weeks 5 Kind of , The corresponding sequence is shown in the following figure :
The first 1 List minutes 1~59 Per minute * perhaps */1 Express
The first 2 List hours 1~23(0 Express 0 spot )
The first 3 List date 1~31
The first 4 List month 1~12
The first 5 Column ID week 0~6(0 Sunday )
The first 6 List the commands to execute
* * * * * command
Time sharing day month week Commands for scheduling scripts
Continue with some examples , Suppose I want to be in the early morning every day 1 spot 30 Sub scheduling at /home/data/ The next path run.py The file of , Then write like this :
30 01 * * * python3 /home/data/run.py
branch when Sun Moon week python Absolute path /py Script
There are a few more things to note crontab The operator of :
*( asterisk ): This operator specifies all available values for the field . for instance , In the hour field , An asterisk is equivalent to every hour ; In the month field , An asterisk is equivalent to every month
,( comma ): It means to divide time . for instance , If the work to be performed is daily 2 Point and 4 Some time , That's how it's written
0 2,4 * * * command
-( minus sign ): For a period of time , for instance ,8 Point to 12 Every hour between points 20 Do one job at a time :
20 8-12 * * * command
In fact, it is equivalent to
20 8,9,10,11,12 * * * command
/n( Oblique line ):n On behalf of the digital , That is, every n Unit interval , For example, every five minutes , be :
*/5 * * * * command
crontab Use steps and related operations :
1、 The installation log is used to check whether the task is actually executed
2、 start-up crontab, The first 1、2 This step is only required for initial use , Then go to step 3 directly .
3、 edit crontab Mission , You'll need one vim file
Edit at the end of the document . This means that a blank file will be created in the directory every minute .
4、 After adding crontab After the command , Press ctrl + o, Then press enter , Press ctrl +x Exit the editor , The server will display :installing new crontab, representative crontab Insert the success .
5、 We can use crontab -l Check what scheduling tasks have been added
6、 Check the execution through the log
7、 It can be used crontab -r Delete crontab Mission
windows Task scheduler
windows Task planner for advantage Obviously , Don't write commands , Operate graphically .
shortcoming Also obvious : It is necessary to keep the computer from shutting down and running directly during the scheduled time python Script , Need to put py Pack it up exe.
First of all, let's talk about how to python The script is wrapped in exe Program , This one is very simple .
1、 install pyinstaller library
pip install pyinstaller
2、 take D disc Data The folder run.py pack exe
pyinstaller -F D:\Data\run.py
3、 The production of exe The file will be automatically generated dist Under the folder
It's packed exe after , say something windows How to use the task scheduler ?
1、 Open task scheduler
Right click the computer → management → Task scheduler
2、 Create basic tasks
Create basic tasks → Enter task name → trigger ( Select the trigger time or trigger rule )
→ operation ( Choose start program / Send email / display messages , Because we are running py Script , So choose to start the program ) → Start the program ( choice python The script exe) → complete .
The two scheduling methods have been summarized , Thank you for reading !
边栏推荐
- E-week finance Q1 mobile banking has 650million active users; Layout of financial subsidiaries in emerging fields
- How QT sets some areas to be transparent in the background image
- Four characteristics of transactions
- 关于 SAP UI5 参数 $$updateGroupId 前面两个 $ 符号的含义
- What kind of experience is it to read other people's code
- [xman2018 qualifying] pass
- [advanced MySQL] MTS master-slave synchronization principle and Practice Guide (7)
- [daily 3 questions (3)] maximum number of balls in the box
- Elegant custom ThreadPoolExecutor thread pool
- Redis持久化
猜你喜欢
Practice of constructing ten billion relationship knowledge map based on Nebula graph
Tsinghua & Shangtang & Shanghai AI & CUHK proposed Siamese image modeling, which has both linear probing and intensive prediction performance
清华&商汤&上海AI&CUHK提出Siamese Image Modeling,兼具linear probing和密集预测性能!...
Redis persistence
[business security-04] universal user name and universal password experiment
反射学习总结
Design and implementation of food recipe and ingredients website based on vue+node+mysql
请求一下子太多了,数据库危
Synchronized and lock escalation
Professor huangxutao, a great master in CV field, was born at the age of 86. UIUC specially set up a doctoral scholarship to encourage cutting-edge students
随机推荐
A brief analysis of the differences between domestic and foreign e-commerce
Domestic database disorder
初识云原生安全:云时代的最佳保障
PostgreSQL 15新版本特性解读(含直播问答、PPT资料汇总)
Resolve activity startup - lifecycle Perspective
Integration of entry-level SSM framework based on XML configuration file
Reflection learning summary
清华&商汤&上海AI&CUHK提出Siamese Image Modeling,兼具linear probing和密集预测性能!...
Référence forte, faible, douce et virtuelle de threadlocal
Redis CacheClient
PCL Library - error reporting solution: cmake and Anaconda conflicts during installation
Sword finger offer II 039 Histogram maximum rectangular area monotonic stack
élégant pool de threadpoolexecutor personnalisé
【每日3题(3)】盒子中小球的最大数量
基于SSM的Web网页聊天室系统
Jupiter core error
注解学习总结
Daily 3 questions (1): find the nearest point with the same X or Y coordinate
【业务安全-02】业务数据安全测试及商品订购数量篡改实例
June 27, 2022 Daily: swin transformer, Vit authors and others said: a good basic model is the simple pursuit of CV researchers