2012-11-04 147 views
0

我试图建立一个crontab我在当前用户我目前的工作有这样我登录到bash脚本与crontab的

* * * * * /CS/day/get_info.sh 

get_info.sh应该是每分钟输出的文本文件我怀疑它会在脚本所在的目录中输出一个文件,但它不会。

我也检查了系统日志,看看我能否弄清楚。

(user) CMD (/CS/day/get_info.sh) 
(user) MAIL (mailed 46 bytes of output but got status 0x0001#012) 

有人可以向我解释为什么会发生这种情况吗?

感谢

回答

0

脚本在用户的主目录,并运行该文件应该有作为。如果你想在同一目录中的脚本,或者在你的脚本做cd或修改您的crontab条目:

*/1 19-20 * * * cd /CS/day; /CS/day/get_info.sh 

另一个常见的问题crontab项是环境。如果脚本正常工作在你的终端,尝试调试它,当它从cron运行:

40 11 * * * bash -x /CS/day/get_info.sh >/tmp/get_info.sh.log 2>&1 

运行一次只与当前的时间,否则你将覆盖每分钟你的日志文件。

+0

我检查了是否会在主目录中创建文件,并且没有用* * * * * /CS/date/get_info.sh – user1709294

+0

创建任何东西请参阅我的修改答案。 –

1

man cron告诉你:

When executing commands, any output is mailed to the owner of the 
    crontab (or to the user named in the MAILTO environment variable in the 
    crontab, if such exists). The children copies of cron running these 
    processes have their name coerced to uppercase, as will be seen in the 
    syslog and ps output. 

所以,你必须

  • cd到相应的目录自己(cron将会使用$HOME
  • 重定向任何输出您选择的文件

你可以在crontab中做这两件事情。但我建议做脚本本身的第一行:

#!/bin/bash 
cd WHEREEVER_YOU_WANT 
exec > YOUR_LOG_FILE 2&>1 
0

在我的情况下,我不得不安装和配置SMTP客户端。