iT邦幫忙

1

[已解決]Linux Shell Script 直接執行與crontab排程執行後結果不同

/root/diskstatus.sh 內容如下
#/bin/bash
smartctl -a /dev/sda |grep 'Test_Description' -A 1 |mail -v -s "Proxy Disk Status" xxx@abc.com
直接執行/root/diskstatus.sh 可收到信內容
Num Test_Description Status Remaining LifeTime(hours) LBA_of_first_error
#1 Short offline Completed without error 00% 47452

crontab -e內容如下
0 8 * * * /root/diskstatus.sh

排程由crontab執行後
有收到信,但內容一片空白,請問該如何解決,感謝~

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

2
bizpro
iT邦大師 1 級 ‧ 2018-02-27 14:03:06
最佳解答

crontab的環境變數和bash的不同, 一個習慣是, 在bash中都使用全路徑指令, 建議:

$ cat /root/diskstatus.sh
#/bin/bash
/usr/sbin/smartctl -a /dev/sda |/bin/grep 'Test_Description' -A 1 |/usr/bin/mail -v -s "Proxy Disk Status" xxx@abc.com
vicentli iT邦研究生 4 級 ‧ 2018-02-27 16:49:43 檢舉

非常感謝!

我要發表回答

立即登入回答