解决mail: command not found
今天使用脚本来监控系统状态,为了把每天系统状态记录下来并发到邮箱里,我写了个脚本来实现,但在发邮件的过程中出现了mail: command not found.
系统:centos 5.9
脚本内容:
#!/bin/bash
dug=$(df -h | grep "/$" | awk '{print $4}' | awk -F% '{print $1}')
cug=$(expr 100 - $(mpstat | tail -1 | awk '{print $10}' | awk -F. '{print $1}'))
mug=$(expr $(free | grep "cache:" | awk '{print $3}') \* 100 / $(free | grep "Mem:" | awk '{print $2}'))
alog="/root/alert.txt"
AMAIL="root@localhost.localdomain"
if [ $dug -gt 3 ]
then
echo "Disk usage:$dug%" >> $alog
fi
if [ $cug -gt 2 ]
then
echo "cpu usage:$cug%" >> $alog
fi
if [ $mug -gt 2 ]
then
echo "Memory usage:$mug%" >> $alog
fi
if [ -f $alog ]
then
cat $alog | mail -s "Host Alert" $AMAIL
rm -fr $alog
fi
解决办法:
yum -y install mailx sysstat
http://sharadchhetri.com/2013/02/13/mail-command-not-found-in-redhat-centos-or-ubuntu/
mail command not found
Whenever any message says while hitting the command as Command Not Found , it means the package is not installed or script is not present.
For the mail command not found issue install the mailx.
Use the below given command for mailx installation.
For Redhat/CentOS =>
yum install mailx
For Debian or Ubuntu =>
sudo apt-get install mailutils
来自 http://blog.csdn.net/cheng_fangang/article/details/9493585
http://m.blog.csdn.net/blog/chengfangang/9493585