Cronjob脚本失败但手动运行正常

时间:2012-04-11 10:36:51

标签: aix

我有手动运行的脚本,但在通过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

1 个答案:

答案 0 :(得分: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。