我不熟悉脚本,如果系统上有更新,我正在尝试向自己发送电子邮件。我想这样做的方式是,如果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