crontab每六个小时执行一次(linux 新手提问,我有一段程序,test.py,想让linux每隔6小时执行一次,如何实现)

本文目录
linux 新手提问,我有一段程序,test.py,想让linux每隔6小时执行一次,如何实现
我也来补充下,除了楼上提出的crontab外,还可以使用python自带的定时任务库sched
使用crontab不用更改代码,到点执行
但是如果是sched库,你得再添加代码
import time
import sched
schedule = sched.scheduler(time.time, time.sleep)
def recycle_eval(delay=6*60*60):#默认定时6小时执行
schedule.enter(delay, 0, recycle_eval, (delay,))
#此处添加你要执行的代码
if __name__ == ’__main__’:
schedule.enter(2, 0, recycle_eval, (,))
schedule.run()
常驻后台执行的话用nohup命令执行这个脚本
nohup python /path/to/your/script.py &
linux centos 我想设置个定时cron任务
1.系统级别的计划任务:
/etc/crontab文件
vim /etc/crontab
* */6 * * * find /tmp/eaccelerator/ -type f -print -delete
保存退出
2.如果是root用户:
crontab -e -u root
* */6 * * * find /tmp/eaccelerator/ -type f -print -delete
保存退出
如果是其他用户,只需把-u后面的改为用户名即可。
3.最后检查一下crond是否开机启动,一般默认就是开机启动的。
chkconfig --list crond
4.查看用户计划任务
crontab -l -u user (user为查看的用户名)

更多文章:
form表单制作(为什么制作的form表单会在网页显示中多出一行)
2026年10月11日 09:10
teammate(teammate,company,partner)
2026年10月11日 06:10
javascript arraybuffer(javascript可以把base64编码转换成二进制代码吗求示例代码!)
2026年10月11日 04:00
text函数公式(excel中round和text函数的区别是什么)
2026年10月11日 03:50
google chrome打不开(chrome浏览器打不开怎么回事 浏览器打不开的处理方法)
2026年10月11日 02:00
websocket整合springboot(Springboot整合Websocket遇到的坑)
2026年10月11日 01:40
drawerlayout(android 怎样让drawerlayout设置的侧滑菜单的内容充满屏幕)
2026年10月10日 19:20
xor四位数怎么运算(单片机怎样用C语言实现4个数字间的异或)
2026年10月10日 17:50


