Think before you speak, read before you think.

shell下通过ping判断网络是否断开

 

#!/bin/bash
#for use:
#author: [email protected]
#modified by xx at date
#version:
#history:
#relate on:
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
netstat=$(ping -c3 g.cn|grep transmitted |awk '{print $4}')
if((netstat==0))
#time out
then
        date >> network.down.log
else
#ok
        echo "network is ok"
fi

 

 

ping 命令学习

ping 默认是每秒钟一次,如果需要更改时间,可以 -i interval, 只有 root 可以写小于 0.2 秒的时间。

ping -i 5 223.5.5.5
ping -i 0.1 223.5.5.5

ping 本地回环地址有三种方式

ping 0
ping localhost
ping 127.0.0.1

ping 具体次数结束,如 100 次

ping -c 100 jpuyy.com

使用 flood 方式 ping

ping -f 0

只显示 ping 的结果

ping -c 5 -q 127.0.0.1

设置发送的 ping 包大小 -s 单位是 bytes, ping 自带的 header 头大小 28 bytes

ping -s 1000 jpuyy.com

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *