网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

ubuntu怎么定时执行python脚本

这篇文章主要介绍了ubuntu怎么定时执行python脚本的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇ubuntu怎么定时执行python脚本文章都会有所收获,下面我们一起来看看吧。

创新互联专注于企业营销型网站、网站重做改版、北海街道网站定制设计、自适应品牌网站建设、成都h5网站建设购物商城网站建设、集团公司官网建设、外贸网站建设、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为北海街道等各大城市提供网站开发制作服务。

crontab

编辑定时任务

crontab -e

参数定义:

  • -u 指定用户, - -l 列出用户任务计划,

  • -r 删除用户任务,

  • -e 编辑用户任务

英文介绍:

# 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/

中文解释:

格式

m h dom mon dow command

以上为缩写,这里提供全拼对照:

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

含义如下:

  • m 每个小时的第几分钟执行该任务

  • h 每天的第几个小时执行该任务

  • dom 每月的第几天执行该任务

  • mon 每年的第几个月执行该任务

  • dow 每周的第几天执行该任务 - command 指定要执行的程序

分      小时    日      月       星期     命令
0-59   0-23   1-31   1-12     0-6     command

其他:

  • 其中星期中0表示周日。

  • * 代表任何时间,比如第一个分钟,用 * 就代表每一小时的每一分钟都执行

  • - 表示区间,比如1-3

  • , 如果区间不连续,可以用,例如1,3,6    编辑完成后wq 保存退出

重启服务

service cron restart

注意事项

注意,一定要用绝对路径。否则可能会执行失败。

比如,我们要执行

python bwh.py

那么你需要干的第一件事是

which python

以此来查看python命令的真正路径

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

然后,查看bwh.py的全路径,在bwh.py所在文件夹下

pwd
/app/python/blog

然后路径便为

/app/python/blog/bwh.py

所以整条记录应该这样编辑

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

上面的记录是指每天9点整执行/root/.pyenv/shims/python /app/python/blog/bwh.py并将打印日志输出到/tmp/new_blog_bwh.log

关于“ubuntu怎么定时执行python脚本”这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对“ubuntu怎么定时执行python脚本”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注创新互联行业资讯频道。


分享题目:ubuntu怎么定时执行python脚本
URL标题:http://bjjierui.cn/article/jhhpei.html

其他资讯