作为cron作业运行小脚本时出现问题


Problem running a small script as cron job

我是问题调度和运行脚本通过cron作业。我在linux (ubuntu)上,它是一个VPS。我所做的是把这一行放在crontab文件中,在这里:/etc/crontab我写:

*/15 *    * * *   www-data  php /var/www/abs/phpscript.php

我把777赋给文件,在crontab中写完上面的内容后,我运行命令:

crontab crontab

然后过了一段时间,我在我的/var/mail/username文件中收到了邮件,上面写着:/bin/sh: root: not found

所以我不明白是什么问题。

我也运行了phpinfo,它显示第三个变量为APACHE,这可能意味着PHP是作为APACHE模块运行的。

请说出可能的解决方案。

提前感谢每一个试图解决我的问题的人。

您也可以尝试使用"wget -q -O"来运行它

*/15 * * * * lynx -dump "url"  > /dev/null

Wget例子:

*/15 * * * * wget -O /dev/null 'http://www.mydomain.com/document.php?&user=myuser&password=mypass' >/dev/null

如果你需要发布数据,你可以使用

——post数据"登录= user&密码=通过"

*/15 * * * * wget -O /dev/null 'http://www.mydomain.com/document.php?&user=myuser&password=mypass' --post-data 'foo=bar' >/dev/null

如果您编辑了/etc/crontab,您应该重新阅读文件顶部的警告:

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

/etc/crontab文件上运行crontab(1)可能污染了根用户的 crontab(5)文件(存储在/var/spool/cron/crontabs/中的文件)。我建议运行crontab -e 作为root来编辑crontab文件,并删除所有与/etc/crontab相同的条目。(可能您只是污染了您自己的crontab(5)—如果crontab -e作为根没有显示任何内容,请在您自己的个人帐户下运行crontab -e,看看系统范围内的条目是否复制到您自己的crontab(5)中。)

我不知道你在哪个文件上运行chmod 777,但这可能是不必要的。您确实应该将权限设置得尽可能严格,以限制恶意攻击或无意错误的结果。

您正在以用户身份运行crontab,这意味着您不能在cron中指定用户。

您所借鉴的示例模板是用于系统(根)cron的。

删除用户名并重试