版本1
check.sh:
#!/bin/bash
source .bash_profile
i=`ps -ef | grep /usr/local/PostgreSQL/9.6/data/ | grep -v grep | wc -l`
if [ $i -lt 1 ]
then
text='process cannot find. The upgrade job is done.please help to vacuum'
echo "$text" | /bin/mail -s "192.168.15.32 pg_upgrade" barry.chen@coresolutions.com,andy.wong@coresolutions.com,murphy.leung@coresolutions.com
fi
但发现一个问题:
-bash: mail: command not found
呵呵,显然mailx没有安装,于是:
yum -y install mailx
把check.sh 设置crontab ,每一分钟跑一次
*/1 * * * * /root/check.sh > /dev/null 2>&1
发现版本1中要进程不存在时发完一封邮件后会,接下来的每一分钟会不断的发一封。
修改脚本为当检测进程不存在时发完一封邮件后,下次的每一分钟停止发送
版本2
check2.sh
#!/bin/bash
source .bash_profile
TEMP_FOLDER=/root
i=`ps -ef | grep /var/lib/pgsql96/data/ | grep -v grep | wc -l`
generateDoneFile() {
echo `date "+%Y-%m-%d %H:%M %z %Z"`>${TEMP_FOLDER}/$1.done
}
if [ -e ${TEMP_FOLDER}/sendemail.done ];
then
echo "already sendemail"
exit 10
else
if [ $i -lt 1 ]
then
text='process cannot find. The upgrade job is done.please help to vacuum'
echo "$text" | /bin/mail -s "192.168.15.30 ECI pg_upgrade" barry.chen@coresolutions.com
generateDoneFile sendemail
fi
fi