crontab无法执行且(root) MAIL (mailed 54 bytes of output but got status 0x004b#012错误

今日在一台阿里云主机使用crontab,发现脚本无法执行,状态:

  • shell脚本已经有执行权限chmod +x xxx.sh
  • sh文件第一行加上了she-bang:#!/bin/bash
  • 确认 crond 服务正常运行(service crond status)
  • crontab 文件正确无误
  • 脚本可以手动执行但不能自动执行

查错:
tail /var/log/cron发现如下错误:

Mar 19 23:03:01 Aliyun crond[613]: (root) RELOAD (/var/spool/cron/root)
Mar 19 23:03:01 Aliyun CROND[32696]: (root) CMD (/root/move_pic.sh)
Mar 19 23:03:01 Aliyun CROND[32695]: (root) MAIL (mailed 54 bytes of output but got status 0x004b#012)

然后看/var/log/maillog文件:

cat  /var/log/maillog
#返回如下信息:
Mar 19 23:03:01 AliyunHZ1 postfix/sendmail[32698]: fatal: parameter inet_interfaces: no local interface found for ::1

搜索一番,这样解决:

  1. 编辑/etc/postfix/main.cf文件,把inet_interfaces = all这一行前面的注释符号取消。
  2. 注释掉inet_interfaces = localhost
  3. service postfix start

此时可以正常发送mail了。如果脚本执行错误可以通过mail命令查看邮件。在mail程序中,输入序号查看邮件,输入d删除邮件,输入q退出。

根本原因:
脚本错误->需要将错误信息发送到mail->设置错误导致无法发送mail->cat /var/log/cron中提示发送mail错误

但是我的脚本可以手动执行又是怎么回事?
因为我用了这样的句子:

mv $uploadpath/*.* /var/ftp/ftppath/

这样的句子在crontab中被扩展了,所以改为类似下面的句子就好了:

mv /abs/path/*.jpg /var/ftp/ftppath/
发布了227 篇原创文章 · 获赞 148 · 访问量 34万+

猜你喜欢

转载自blog.csdn.net/toopoo/article/details/104979615