2012-04-11 82 views
2

我有手动运行的脚本,但运行通过cronjob时没有得到所需的输出。如果脚本有任何问题,请告诉我。Cronjob脚本失败,但手动运行良好

#!/usr/bin/ksh 

file1=$(find *-* -mtime 1) 

file2=$(find *-* -mtime 2) 


basefile1=$(basename $file1) 
basefile2=$(basename $file2) 


cd /gtxappl/Release/SCMAudit 

./cmp.sh $basefile1 $basefile2 > dailyAuditChecks.txt 

mailx -s "Daily Checks Report" ****@homeretailgroup.com < dailyAuditChecks.txt 

回答

4

Admin's Choice

 
5. Crontab Environment 
cron invokes the command from the user’s HOME directory with the shell, (/usr/bin/sh). 
cron supplies a default environment for every shell, defining: 
HOME=user’s-home-directory 
LOGNAME=user’s-login-id 
PATH=/usr/bin:/usr/sbin:. 
SHELL=/usr/bin/sh 
Users who desire to have their .profile executed must explicitly do so in the crontab entry or in a script called by the entry. 

我建议使用绝对路径尽可能,如果你需要的环境变量,不要忘了执行你的.profile文件。

+0

如果有疑问,请在脚本中添加printenv命令以查找环境的实际外观。 – 2012-05-01 02:55:57

相关问题