Linux crontab定时任务

配置

1.编写第一个shell文件 hello.sh
vim hello.sh

#!/bin/bash
echo "hello word !!" >> /www/hello.txt

2、通过chmod命令赋予该脚本的执行权限
chmod 755 hello.sh
3、新增调度任务(5分钟执行一次)
vim /etc/crontab

*/5 * * * * root /www/hello.sh

crond服务

service crond start //启动服务
service crond stop //关闭服务
service crond restart //重启服务
service crond reload //重新载入配置
service crond status //查看服务状态

https://blog.csdn.net/weixin_36211536/article/details/116990991

报错解决

postfix报错postfix: fatal: parameter inet_interfaces: no local interface found for ::1
==》vim /etc/postfix/main.cf
发现配置为:
inet_interfaces = localhost
inet_protocols = all
改成:
inet_interfaces = all
inet_protocols = all
重新启动
service postfix start

crond运行python 文件报错:SyntaxError: invalid syntax

crond运行环境变量与手动执行不同,建议crontab和脚本里无论是命令还是文件路径都用绝对路径
另外,source /etc/profile(这个可以加到脚本里)
https://blog.csdn.net/ranran0224/article/details/76119524

文件过大,crond停止执行

postdrop: warning: uid=0: File too large
sendmail: fatal: root(0): message file too big
postdrop: warning: uid=0: File too large
sendmail: fatal: root(0): message file too big

发表评论

您的电子邮箱地址不会被公开。