cron 輸出不工作

cron 輸出不工作

需要幫助解決這個問題。我有以下腳本 - /root/eximqueue.sh 具有適當的 +x 權限等:

#!/bin/bash
######### Edit here ##########
[email protected] # Set this to your email id to receive alerts on mail queue
_limit=20 # Set the limit here

##############################

clear;
_result="/tmp/eximqueue.txt"
_queue="`exim -bpc`"

if [ "$_queue" -ge "$_limit" ]; then
echo "Current queue is: $_queue" > $_result
echo "Summary of Mail queue" >> $_result
echo "`exim -bp | exiqsumm`" >> $_result
mail -s "Number of mails on `hostname` : $_queue" $_mail_user < $_result
cat $_result
_message_id="`exiqgrep -i -f [email protected] | xargs exim -M`"
fi

rm -f $_result

然後我設定了 cron,檢查了我的 crons (crontab -l) 及其存在:

*/5 * * * * /bin/sh /root/eximqueue.sh

檢查了我的 cron 日誌

grep eximqueue /var/log/cron

……及其運行(僅舉幾個例子):

Oct 12 14:00:01 osi CROND[28191]: (root) CMD (/bin/sh /root/eximqueue.sh)
Oct 12 14:05:01 osi CROND[30877]: (root) CMD (/bin/sh /root/eximqueue.sh)
Oct 12 14:10:01 osi CROND[893]: (root) CMD (/bin/sh /root/eximqueue.sh)
Oct 12 14:15:01 osi CROND[4429]: (root) CMD (/bin/sh /root/eximqueue.sh)

問題是,我沒有收到任何來自腳本的電子郵件!但是,如果我直接運行它 - 它會完美運行並且我會收到電子郵件。有想法嗎?

答案1

問題是,當腳本從 cron 啟動時,路徑比直接從 bash 運行它時要短得多。

只需將對程式的呼叫替換為它們的完整路徑。/usr/sbin/exim而不是exim例如(或你安裝了 exim 的地方)。

相關內容