原文链接:https://vien.tech/article/157
前言
本文将介绍ubuntu系统下如何定时执行shell脚本、python脚本,ubuntu系统有一个定时任务的管理器crontab,我们只需要编辑定时任务,然后重启定时任务服务就好了。
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
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对的支持。
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
- 袁培华.1992-有缘【歌林】【WAV+CUE】
- 王瑞霞.1996-是我太软心【名冠】【WAV+CUE】
- 《谭维维 30首经典流行歌曲精选辑 2CD》[WAV/分轨][1.1GB]
- 《赵传 出道三十年全新大碟 你过得还好吗》[WAV/分轨][460MB]
- 《发烧四大天王 磁性男声HiFi发烧碟 2CD》[WAV/分轨][1GB]
- 黑神话悟空上品鼠司空精魄获取方法一览|上品鼠司空精魄收集攻略
- 《真三国无双:起源》新情报将于9月26日公开,实机演示亮相!
- 黑神话悟空上品鼠禁卫精魄获取方法一览|上品鼠禁卫精魄收集攻略
- 优美的旋律至真的情怀《品茶轻音乐·极品典藏Vol.1CD1》[WAV+CUE]
- 曾嵘《峥嵘岁月DSD(试音碟)》WAV+CUE
- 小提琴天碟AlfredoCampoli坎波利-贝多芬D大调小提琴协奏曲与普罗米修斯作品选FLAC
- 博主称本周游戏业内动荡无比:高价PS5 Pro、Xbox裁员等
- 米哈游也搞AI?米哈游AI大模型Glossa完成备案
- G胖变G瘦后:玩家担心其健康状况:如果他出事 游戏业将发生巨变
- 群星.1995-SUMMER.PASSION.REMIX【宝丽金】【WAV+CUE】