我不熟悉腳本,如果系統上有更新,我正在嘗試向自己發送電子郵件。我想這樣做的方式是,如果yum check-update報告任何軟件包,給我發一封電子郵件,如果什麼也不做。這是我想出了:如果聲明問題
#!/bin/bash
cat /dev/null > /root/scripts/updates.txt
yum check-update > /root/scripts/updates.txt
updatecheck=$(cat /root/scripts/updates.txt | grep updates | grep -v mirrors)
updatestatus=$(echo "$updatecheck" | wc -l)
if [ $updatestatus == 0 ]
then
mail -s "There are no updates for monitor01.aevhosting.com" [email protected]
else
mail -s "There are updates for monitor01.aevhosting.com" [email protected]
fi
它沒有做任何事情,它只是掛在那兒,並回到命令行我要控制+ c退出腳本。我還拖尾郵件,看看它是否發出任何東西,但事實並非如此。不知道這裏有什麼問題,但任何和所有的幫助將非常滿意!
謝謝
第一行似乎沒有必要;該文件將在下一行運行'yum'時創建。 – chepner 2014-09-19 15:00:49
'mail'命令是否適用於我們的命令行? – anubhava 2014-09-19 15:02:11
'貓... | grep'是一種反模式,'grep'接受文件就好了,它不需要管道輸入。 – 2014-09-19 15:03:31