
#!/bin/bash
Timeout=0;
Timeout_limit=1;
Timeout_flag=0;
IP="8888"
while [ 1 ]
do
# 取平均延迟的整数位
Timeout="`ping $IP -c 3 | grep 'min/avg/max/mdev'|awk '{print $4}'|cut -b '7'`"
if [ $Timeout -ge $Timeout_limit ] && [ $Timeout_flag -ne 1 ]; then
echo ping timeout, average delay=$Timeout ms
mail -s 'Ping Delay' 邮箱 < ar/log/bootlog
Timeout_flag=1
fi
if [ $Timeout -lt $Timeout_limit ] && [ $Timeout_flag -ne 0 ]; then
echo ping recovery, average delay=$Timeout ms
mail -s 'Ping recovery' 邮箱 < ar/log/bootlog
Timeout_flag=0
fi
sleep 5
done第三行Timeout_limit值写错了,应该是100哈,代码提交了不能改了。你这个不需要把延迟结果保存在文件的,而是应该需要作定时检测的。
我的需求是PING这个地址 只要延迟高于100ms就发送个邮件 然后正常后在发个邮件通知 之后正常不发 一有延迟就发 我这个老是重复 求高人指点 #!/bin/bashIP=`ping 8888 -c 3|sed -n "2p" |awk '{print $7}'|cut -f 2 -d "="|cut -f 1 -d ""`L='100'a='tail -1 /opt/texttxt' | sed -n '1p'i='tail -1 /opt/text1txt' | sed -n '1p'echo "$IP" >> /opt/texttxtecho "$IP" >> /opt/text1txtif [[ $a -le $L ]]thenmail -s 'yanchi' 邮箱 < ar/log/bootlogelif [[ $a -ge $L ]];thenmail -s 'huifu' 邮箱 < ar/log/bootlogelseecho "ok"fi~我是想把这个延迟数写进一个文件里进行对比 延迟是会报 但是正常后不报 ,而且正常情况下运行还会发送 谁能帮忙看看
useradd 命令用于创建用户passwd 命令用于设置密码echo 命令用于输密码文件scp 命令用于发送文件 tom 用户例其设置密码123456并发送1721613机器/home/tom目录:
useradd tom
PASSWD="123456"
echo -e "$PASSWD\n$PASSWD" | passwd tom
echo $PASSWD > passwd_file
scp passwd_file 1721613:/home/tom
希望帮助
#!/bin/bash
while :
do
#包大小
PACKETSIZE=32
#发包数
PACKETTIMES=10
#间隔时间
INTERVAL=1
#ip列表文件位置
IPFILE=/tmp/1
#多长时间测试一次(秒)
SLEEPTIME=60
#临时文件
TMP=/tmp/pingtmp
#输出的pingtxt文件路径
OUTPUT=/tmp/pingtxt
#本机IP(这都不知道自己切JJ)
HOSTIP=1111
while read line
do
> ${TMP}
ping -c ${PACKETTIMES} -i ${INTERVAL} -s ${PACKETSIZE} $line >> ${TMP}
DELAY=`grep rtt ${TMP} | awk '{print$4}' |awk -F "/" '{print$1"/"$2"/"$3}'`
LOST=`grep loss ${TMP} |awk -F "%" '{print$1"%"}'|awk '{print $NF}' `
DATE=`date +"%Y-%m-%d %H:%M:%S"`
if [ -z "${DELAY}" ]
then
DELAY=none
fi
echo "################################################" >> ${OUTPUT}
echo "${DATE} ${HOSTIP} > ${line} the min/avg/max is ${DELAY} and packets lost ${LOST}" >> ${OUTPUT}/pingtxt
rm -rf ${TMP}
done<${IPFILE}
sleep ${SLEEPTIME}
done
= =缺点是 运行时候 要加个 /脚本 & 后台执行
1、shell的内建命令,用户可以直接输入命令名称执行。比如pwd、cd等命令。用户可以通过type命令来判断命令是内建命令还是外部命令。
2、shell的外部命令,shell程序会根据PATH变量中的路径查找相应的外部命令,如果命令在PATH变量的路径中,用户可以直接输入命令名称来执行,比如cat、grep、ping等都是外部命令。
3、如果shel外部命令不在PATH环境变量的路径中,则需要通过“”命令来执行程序或者脚本文件。
[root@localhost ~]# ping -h
Usage: ping [-LRUbdfnqrvVaA] [-c count] [-i interval] [-w deadline]
[-p pattern] [-s packetsize] [-t ttl] [-I interface or address]
[-M mtu discovery hint] [-S sndbuf]
[ -T timestamp option ] [ -Q tos ] [hop1 ] destination
[root@localhost ~]# ping -c 5 127001
PING 127001 (127001) 56(84) bytes of data
64 bytes from 127001: icmp_seq=1 ttl=64 time=370 ms
64 bytes from 127001: icmp_seq=2 ttl=64 time=0032 ms
64 bytes from 127001: icmp_seq=3 ttl=64 time=0034 ms
64 bytes from 127001: icmp_seq=4 ttl=64 time=0034 ms
64 bytes from 127001: icmp_seq=5 ttl=64 time=0050 ms
--- 127001 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4002ms
rtt min/avg/max/mdev = 0032/7432/37012/14790 ms
以上就是关于Linux下shell脚本PING命令只要延迟高于100ms就发送个邮件全部的内容,包括:Linux下shell脚本PING命令只要延迟高于100ms就发送个邮件、linux 求助shell脚本 ping命令延迟超过100ms的包就发邮件 恢复正常也发个邮件 之后不用发、写个shell脚本,使用ping命令探测172.16.250.1到172.16.250.254之间等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)