Linux下Python脚本自启动和定时启动的详细步骤
作者:selfcs 时间:2022-08-13 20:51:22
一、Python开机自动运行
假如Python自启动脚本为 auto.py
。那么用root权限编辑以下文件:
sudo vim /etc/rc.local
如果没有 rc.local
请看 这篇文章
在exit 0上面编辑启动脚本的命令
/usr/bin/python3 /home/selfcs/auto.py > /home/selfcs/auto.log
最后重启Linux,脚本就能自动运行并打印日志了。
二、让Python脚本定时启动
用root权限编辑以下文件
sudo vim /etc/crontab
在文件末尾添加以下命令
2 * * * * root /usr/bin/python3 /home/selfcs/auto.py > /home/selfcs/auto.log
以上代码的意思是每隔两分钟执行一次脚本并打印日志。
三、crontab编写解释
基本格式
* * * * * user command
分 时 日 月 周 用户 命令
3.1 举例说明 1、每分钟执行一次
* * * * * user command
2、每隔2小时执行一次
* */2 * * * user command (/表示频率)
3、每天8:30分执行一次
30 8 * * * user command
4、每小时的30和50分各执行一次
30,50 * * * * user command(,表示并列)
5、每个月的3号到6号的8:30执行一次
30 8 3-6 * * user command (-表示范围)
6、每个星期一的8:30执行一次
30 8 * * 1 user command (周的范围为0-7,0和7代表周日)
总结
以上所述是小编给大家介绍的Linux下Python脚本自启动和定时启动的详细步骤,网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
来源:https://www.linuxidc.com/Linux/2019-09/160739.htm
标签:linux,python,自启动,定时启动
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
PHP 动态随机生成验证码类代码
2024-05-02 17:18:02
![](https://img.aspxhome.com/file/2023/3/129823_0s.jpg)
深入理解python中sort()与sorted()的区别
2021-08-17 11:46:49
python写的ARP攻击代码实例
2023-05-23 19:45:46
python生成随机红包的实例写法
2021-02-20 12:30:33
远程连接阿里云SqlServer 2012 数据库服务器的图文教程
2024-01-16 06:16:48
![](https://img.aspxhome.com/file/2023/9/99989_0s.png)
vue 引用自定义ttf、otf、在线字体的方法
2024-04-30 10:18:47
![](https://img.aspxhome.com/file/2023/2/130292_0s.png)
opencv实现回形遍历像素算法
2021-12-26 01:49:30
![](https://img.aspxhome.com/file/2023/0/128600_0s.jpg)
argparse 模块简介
2023-05-27 10:19:36
![](https://img.aspxhome.com/file/2023/2/117382_0s.png)
分享五个超实用Python脚本,减少垃圾软件负担
2022-07-18 18:38:59
![](https://img.aspxhome.com/file/2023/7/72767_0s.jpg)
Python安装及Pycharm安装使用教程图解
2023-08-01 05:38:06
![](https://img.aspxhome.com/file/2023/0/61460_0s.jpg)
Python paramiko模块使用解析(实现ssh)
2021-02-03 10:29:26
python glom模块的使用简介
2021-08-21 10:22:02
基于numpy中的expand_dims函数用法
2023-02-25 23:24:20
![](https://img.aspxhome.com/file/2023/4/110194_0s.jpg)
理解和使用Oracle 8i分析工具LogMiner
2010-07-16 13:22:00
Vue中金额、日期格式化插件@formatjs/intl的使用及说明
2024-04-27 16:06:48
python读取中文txt文本的方法
2021-06-10 03:55:51
使用python制作一个解压缩软件
2023-04-27 19:08:37
![](https://img.aspxhome.com/file/2023/2/127662_0s.png)
利用Python自带PIL库扩展图片大小给图片加文字描述的方法示例
2022-11-30 20:40:01
![](https://img.aspxhome.com/file/2023/2/98792_0s.jpg)
检测远程文件是否存在
2009-06-22 13:00:00
DreamWeaver制作会移动的广告条
2008-02-03 11:34:00