# cat access_cosmoplat.sh
#/bin/bash
cd /usr/local/scripts/cosmoplat
>.real_log
/usr/bin/curl https://www.cosmoplat.com | grep '沪公网安备31011702004474号' > .real_log
function add_count()
{
count=`cat .count`
b_count=$(($count+1))
echo $b_count>.count
arr=(2 5 10 30 120 250) # 失败2次、5次、10次。。 的时候发报警邮件
echo $b_count
for i in ${arr[@]}
do
[ "$i" == "$b_count" ] && echo "`date +'%Y-%m-%d %H:%M:%S'` - 卡奥斯官网访问失败,请及时处理" | mail -s "卡奥斯官网访问异常 $b_count" xxxxxx@qq.com
# [ "$i" == "$b_count" ] && echo "yes"
done
if [ $b_count -eq 360 ]; then
echo '0'>.count
fi
}
if [ -s .real_log ]; then
date +'%Y-%m-%d %H:%M:%S' >> success.cosmoplat.log
echo '0' >.count
else
date +'%Y-%m-%d %H:%M:%S' >> fail.cosmoplat.log
add_count
fi
## crontab设置每分钟检测一次
*/1 * * * * /usr/local/scripts/cosmoplat/access_cosmoplat.sh
具体mailx自动发邮件,参考: