2012-04-11 114 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

相關問題