当前位置:网站首页>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
* * * * * commandTime 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.pybranch 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 * * * commandIn 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 * * * * commandcrontab 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 pyinstaller2、 take D disc Data The folder run.py pack exe
pyinstaller -F D:\Data\run.py3、 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 !
边栏推荐
- CV领域一代宗师黄煦涛教授86岁冥诞,UIUC专设博士奖学金激励新锐
- 机械硬盘和ssd固态硬盘的原理对比分析
- [microservices sentinel] hotspot rules | authorization rules | cluster flow control | machine list
- What are the operating modes of the live app? What mode should we choose?
- [xman2018 qualifying] pass
- 【每日3题(3)】盒子中小球的最大数量
- Experience sharing of mathematical modeling: comparison between China and USA / reference for topic selection / common skills
- Buuctf Misc
- Make a ThreadLocal (source code) that everyone can understand
- 高德地图IP定位2.0备份
猜你喜欢
![[advanced MySQL] MTS master-slave synchronization principle and Practice Guide (7)](/img/d6/1b916f49ad02dee4ab2c26add324df.png)
[advanced MySQL] MTS master-slave synchronization principle and Practice Guide (7)
![[business security-02] business data security test and example of commodity order quantity tampering](/img/0f/c4d4dd72bed206bbe3e15e32456e2c.png)
[business security-02] business data security test and example of commodity order quantity tampering

Hyperledger Fabric 2. X custom smart contract

LVI: feature extraction and sorting of lidar subsystem

AI begets the moon, and thousands of miles share the literary heart

清华&商汤&上海AI&CUHK提出Siamese Image Modeling,兼具linear probing和密集预测性能!...

Redis持久化

ReentrantLock、ReentrantReadWriteLock、StampedLock
![[PHP code injection] common injectable functions of PHP language and utilization examples of PHP code injection vulnerabilities](/img/19/9827a5e8becfc9d5bf2f51bddf803e.png)
[PHP code injection] common injectable functions of PHP language and utilization examples of PHP code injection vulnerabilities

Use GCC to generate an abstract syntax tree "ast" and dump it to Dot file and visualization
随机推荐
Dynamic Networks and Conditional Computation论文简读和代码合集
【PHP代码注入】PHP语言常见可注入函数以及PHP代码注入漏洞的利用实例
[microservices sentinel] hotspot rules | authorization rules | cluster flow control | machine list
Bidding announcement: Oracle all-in-one machine software and hardware maintenance project of Shanghai R & D Public Service Platform Management Center
Lei Jun lost another great general, and liweixing, the founding employee of Xiaomi No. 12, left his post. He once had porridge to create Xiaomi; Intel's $5.4 billion acquisition of tower semiconductor
Web chat room system based on SSM
基于 Nebula Graph 构建百亿关系知识图谱实践
Hyperledger Fabric 2. X custom smart contract
Sword finger offer II 039 Histogram maximum rectangular area monotonic stack
简析国内外电商的区别
R language objects are stored in JSON
élégant pool de threadpoolexecutor personnalisé
Is there any discount for opening an account now? Is it safe to open an account online?
跨境电商多商户系统怎么选
Redis持久化
Naacl 2022 | TAMT: search the transportable Bert subnet through downstream task independent mask training
ERROR L104: MULTIPLE PUBLIC DEFINITIONS
注解学习总结
Too many requests at once, and the database is in danger
Talk about redis transactions