美文网首页
ubuntu定时任务运行python程序

ubuntu定时任务运行python程序

作者: wuqingfeng | 来源:发表于2022-09-15 10:05 被阅读0次

1. 安装cron软件

apt-get update && apt-get upgrade
apt-get install cron

2. 编辑并启动任务

使用

crontab -e

进入定时任务编辑页面。在文件末尾处增加定时任务

0 2 * * 2L sh /baoke/run.sh

查看当前用户下定时任务

crontab -l -u username

启动定时任务

service cron start

3. 查看定时任务运行情况

使用如下指令:

tail -f /var/log/cron.log

查看定时任务运行状况。
如果系统没有安装rsyslog,可以使用如下指令安装:

apt-get install rsyslog

并编辑配置文件:

vi  /etc/rsyslog.conf

重启日志服务:

service rsyslog restart

以使日志服务生效。

6. 相关文件

为简化cron任务表达式,写了任务脚本:

rm -f /baoke/log/*
time=$(date "+%Y%m%d%H%M%S") 
echo $time >/baoke/log/baoke.log
rm -f /baoke/data/*
/usr/local/bin/python /baoke/code/baoke_online.py >>/baoke/log/baoke.log 2>&1
定时任务定义

0 2 * * 2L sh /baoke/run.sh


# 5. 常见问题
- python程序运行时找不到引入的模块
解决方法:运行python的时候使用python程序全路径

相关文章

网友评论

      本文标题:ubuntu定时任务运行python程序

      本文链接:https://www.haomeiwen.com/subject/hahjortx.html