Copy Code code as follows:
#!/bin/bash
#********************************#
#2013 -01-11 17:00:00 wanggy Exp #
#note:p ing Monitor #
#********************************#
Set-u
Ping_fun ()
{
d_network=192.168.1
Echo-n "Input" network (default $d _network): "
Read Network
: ${network:= $d _network}
echo "Network: $network"
D_hostip_beg=1
d_hostip_end=254
Echo-n "Input" HostIP (default $d _hostip_beg $d _hostip_end): "
Read Hostip_beg Hostip_end
: ${hostip_beg:= $d _hostip_beg}
: ${hostip_end:= $d _hostip_end}
echo "Hostip_beg: $hostip _beg"
echo "Hostip_end: $hostip _end"
If [$hostip _beg-gt $hostip _end];then
echo "$hostip _beg greater than $hostip _end!!!"
Exit 0
Fi
: >pinglog
: >pingerrlog
Ping_count=3
For ((hostip= $hostip _beg;hostip<= $hostip _end;hostip++));d o
{
host= $network. $hostip
echo "Starts ping detection $host"
Ping-c $ping _count $host >/dev/null
If [$ = 0];then
echo "$host is up"
echo "$host is up" >>pinglog
Else
echo "$host is down"
echo "$host is down" >>pingerrlog
Fi
}&
Done
Wait
}
Main ()
{
echo "----Start the ping program----"
Ping_fun
}
Main
Exit 0