广州明生堂生物科技有限公司


shell写的告警次数控制及恢复示例代码

网络编程 shell写的告警次数控制及恢复示例代码 06-22
俺也是新手,写的有点老土,权当练手了,供初学的朋友们参考吧。

#!/bin/bash
if [ $succ_ping -gt $((ping_count-1)) ];then
if [ -f ./alarm_file/alarm_$host ];then
rm -rf ./alarm_file/alarm_$host
#发送故障消除短信通知--调用insert_table
messages="$host服务器通迅恢复正常`date "+%Y%m%d %H:%M:%S"`"
echo "$messages" >>./log/ping_err_recover.log
insert_table
else
echo "本次检测结果---->$host服务器ping检测正常"
echo "`date "+%Y%m%d %H:%M:%S"`--->$host服务器ping检测正常,ping次数$ping_count,接收$succ_ping" >>./log/ping_log
fi
else
echo "本次检测结果---->$host服务器有丢包现象,丢包率为:$loss_ping"
messages="`date "+%Y%m%d %H:%M:%S"`--->$host服务器有丢包现象,丢包率为:$loss_ping"
#对警次数进行处理,超过2次将不告警
#格式host a(告警次数)
#已经出现告警的次数加1
echo "告警服务器为$host"
if [ -f ./alarm_file/alarm_$host ];then
#取出当前的告警次数并加1
a=`awk '{print$2}' ./alarm_file/alarm_$host`
b=$(($a+1))
echo "$host $b" >./alarm_file/alarm_$host
alarm_count=`awk '{print$2}' ./alarm_file/alarm_$host`
if [ $alarm_count -gt $sms_count ];then
echo "超过2次不发送短信"
echo "`date "+%Y%m%d %H:%M:%S"`--->$host服务器有丢包现象,接收$succ_ping,丢包率为:$loss_ping,超过二次不发送。" >>./log/ping_err_log
else
#未超过2次调用insert_table函数发送短信
echo "未超过2次"
echo "`date "+%Y%m%d %H:%M:%S"`--->$host服务器有丢包现象,接收$succ_ping,丢包率为:$loss_ping">>./log/ping_err_log
insert_table
fi
else
#第一次告警
echo "第一次告警"
echo "$host 1" >./alarm_file/alarm_$host
insert_table
echo "`date "+%Y%m%d %H:%M:%S"`--->$host服务器有丢包现象,接收$succ_ping,丢包率为:$loss_ping" >>./log/ping_err_log
fi
fi
done

一个简单的转换输出的shell脚本代码
一个简单的转换输出的shell脚本,从健盘输入a,b,c这种格式输出如下格式:ac#!/bin/bashread-p'请输入:'echo$REPLY.tmp5count=`grep-o','.tmp5|wc-l`echo$countcount_=$((count+1))i

检查linux网络状态的两个脚本
一、通过定时收发email检测网络连通性#/bin/bashecho"Dailytestmail"state.txtmail-sServer_Stateabc@jbxue.comstate.txtrm-df./state.txt~crontab-e增加如下任务1007***/root/checkNKmail&

用来查看linux内存使用情况的shell脚本
在linux中,/proc/$PID/status文件提供了该进程资源(内存,堆栈,信号量,子父进程)的使用情况,虽然linux提供了不少查看内存的命令,但都是看整体的


编辑:广州明生堂生物科技有限公司

标签:服务器,率为,次数,现象,脚本