Crontab 根据需要运行(已修复... 某种程度上)

Crontab 根据需要运行(已修复... 某种程度上)

我在 crontab 中有以下行:

 */30 * * * * /usr/bin/php /home/antoniocs/phpscripts/update-noip/update-noip.php

此脚本更新了我的 no-ip 帐户。它还会将记录写入日志文件,说明它执行了什么和未执行了什么。

这是今天的日志文件:

2009/08/06 11:30 - A tentar buscar ip
2009/08/06 11:30 - Ip encontrado - ***.***.***.***
2009/08/06 11:30 - Ip nao alterado - Abortar acesso ao no-ip
2009/08/06 12:00 - A tentar buscar ip
2009/08/06 12:00 - Ip encontrado - ***.***.***.***
2009/08/06 12:00 - Ip nao alterado - Abortar acesso ao no-ip
2009/08/06 12:30 - A tentar buscar ip
2009/08/06 12:30 - Ip encontrado - ***.***.***.***
2009/08/06 12:30 - Ip nao alterado - Abortar acesso ao no-ip
2009/08/06 13:00 - A tentar buscar ip
2009/08/06 13:00 - Ip encontrado - ***.***.***.***
2009/08/06 13:00 - Ip nao alterado - Abortar acesso ao no-ip
2009/08/06 13:30 - A tentar buscar ip
2009/08/06 13:30 - Ip encontrado - ***.***.***.***
2009/08/06 13:30 - Ip nao alterado - Abortar acesso ao no-ip
2009/08/06 14:00 - A tentar buscar ip
2009/08/06 14:00 - Ip encontrado - ***.***.***.***
2009/08/06 14:00 - Ip nao alterado - Abortar acesso ao no-ip
2009/08/06 14:30 - A tentar buscar ip
2009/08/06 14:30 - Ip encontrado - ***.***.***.***
2009/08/06 14:30 - Ip nao alterado - Abortar acesso ao no-ip
2009/08/06 15:00 - A tentar buscar ip
2009/08/06 15:00 - Ip encontrado - ***.***.***.***
2009/08/06 15:00 - Ip nao alterado - Abortar acesso ao no-ip

从时间戳可以看出,今天它从 11:30 开始,然后于 15:00 停止。

cron 也正在运行:

antoniocs@acsserver:~$ /etc/init.d/cron status
 * cron is running

我不知道为什么会发生这种情况。几天前,它运行起来没有问题(我每 30 分钟在日志中输入一次条目)。我唯一做的事情就是最近升级了我的 Ubuntu 服务器(这导致我有一些其他问题

我做错什么了吗?更新搞乱了 cron 吗?

编辑:

这是我在 2009 年 7 月 8 日 15:00 的系统日志中看到的内容(这是今天的日志,但发生了同样的事情,它在 15:00 之后停止了)

146 Aug  7 15:00:01 acsserver CRON[30775]: Mount of private directory return code [0]
147 Aug  7 15:00:01 acsserver /USR/SBIN/CRON[30786]: (root) CMD ([ -x /usr/sbin/update-motd ] && /usr/sbin/update-motd 2>/dev/null)
148 Aug  7 15:00:01 acsserver /USR/SBIN/CRON[30811]: (antoniocs) CMD (/usr/bin/php /home/antoniocs/phpscripts/update-noip/update-noip.php )
149 Aug  7 15:00:01 acsserver /USR/SBIN/CRON[30810]: (root) CMD ([ -x /usr/sbin/update-motd ] && /usr/sbin/update-motd hourly 2>/dev/null)

似乎没有任何错误:(

编辑2:查看系统日志文件后,我注意到以下几行:

Aug  7 22:10:01 acsserver /USR/SBIN/CRON[6023]: (root) CMD ([ -x /usr/sbin/update-motd ] && /usr/sbin/update-motd 2>/dev/null)
Aug  7 22:17:01 acsserver /USR/SBIN/CRON[6158]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Aug  7 22:20:01 acsserver /USR/SBIN/CRON[6207]: (root) CMD ([ -x /usr/sbin/update-motd ] && /usr/sbin/update-motd 2>/dev/null)
Aug  7 22:30:01 acsserver CRON[6336]: Mount of private directory return code [256]
Aug  7 22:30:01 acsserver /USR/SBIN/CRON[6350]: (root) CMD ([ -x /usr/sbin/update-motd ] && /usr/sbin/update-motd 2>/dev/null)
Aug  7 22:30:01 acsserver /USR/SBIN/CRON[6354]: (antoniocs) CMD (/usr/bin/php /home/antoniocs/phpscripts/update-noip/update-noip.php )
Aug  7 22:30:01 acsserver postfix/sendmail[6367]: fatal: open /etc/postfix/main.cf: No such file or directory
Aug  7 22:39:01 acsserver /USR/SBIN/CRON[6523]: (root) CMD (  [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -type f -cmin +$(/usr/lib/php5/maxlifetime) -print0 | xargs -n 200 -r -0 rm)
Aug  7 22:40:01 acsserver /USR/SBIN/CRON[6574]: (root) CMD ([ -x /usr/sbin/update-motd ] && /usr/sbin/update-motd 2>/dev/null)
Aug  7 22:50:01 acsserver /USR/SBIN/CRON[7044]: (root) CMD ([ -x /usr/sbin/update-motd ] && /usr/sbin/update-motd 2>/dev/null)
Aug  7 23:00:01 acsserver CRON[7173]: Mount of private directory return code [256]
Aug  7 23:00:01 acsserver /USR/SBIN/CRON[7193]: (antoniocs) CMD (/usr/bin/php /home/antoniocs/phpscripts/update-noip/update-noip.php )
Aug  7 23:00:01 acsserver /USR/SBIN/CRON[7195]: (root) CMD ([ -x /usr/sbin/update-motd ] && /usr/sbin/update-motd hourly 2>/dev/null)
Aug  7 23:00:01 acsserver /USR/SBIN/CRON[7196]: (root) CMD ([ -x /usr/sbin/update-motd ] && /usr/sbin/update-motd 2>/dev/null)
Aug  7 23:00:01 acsserver postfix/sendmail[7211]: fatal: open /etc/postfix/main.cf: No such file or directory
Aug  7 23:09:01 acsserver /USR/SBIN/CRON[7390]: (root) CMD (  [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -type f -cmin +$(/usr/lib/php5/maxlifetime) -print0 | xargs -n 200 -r -0 rm)

所以它正在运行 php 脚本。我只是不知道 /etc/postfix/main.cf 是什么。在我的 php 脚本中,我仅使用 curl 来建立一些连接。

编辑3:

看来问题确实出在后缀上。我按照以下说明操作 ->https://help.ubuntu.com/7.04/server/C/postfix.html 并仅设置 cron 抱怨的 main.cf 文件,php 脚本现在似乎没有问题。

仍然不完全理解为什么会发生这种情况。如果有人知道为什么会发生这种情况以及为什么我需要 postfix 来运行我的 php 脚本,请告诉我!!

感谢大家的帮助!

PS:如果有人知道安装错误是什么,也请告诉我:(

答案1

最终的“EDIT 2”日志文件显示您的 postfix 系统设置不正确。当 cron 脚本将输出发送到 stdout 或 stderr(例如,脚本中的任何错误消息)时,它会发送一封电子邮件(默认发送到 root@localhost),而您需要一个正常运行的邮件服务器才能实现这一点。

看起来您的脚本由于其他原因失败了,并且正在向 stderr 或 stdout 写入一些内容,但由于您没有有效的 postfix 设置,因此您正在丢失这些信息。这些错误电子邮件很可能包含您需要的信息,以便找出脚本失败的原因。

当然,这是假设这不是您的错误:8 月 7 日 22:30:01 acsserver CRON[6336]: 私人目录挂载返回代码 [256]

无论哪种方式,您都应该修复您的 postfix 设置。

答案2

我不太明白问题所在。您的 crontab 指示每 30 分钟运行一次 (*/30),并且您的日志每次运行时都会显示 3 行 - 每 30 分钟运行一次。

您能从日志中翻译出什么内容来表明它没有在 :00 和 :30 重新运行吗?

当你说它“在 15:00 停止”时,你的意思是你复制了这个日志并且没有像预期的那样看到 15:30、16:00 等时间的条目?

相关内容