一個可交互的并發(fā)ping檢測腳本
更新時間:2013年02月04日 14:28:05 作者:
可交互的并發(fā)ping檢測腳本,供大家學(xué)習(xí)參考。重點& 跟wait,這樣“并發(fā)”的結(jié)果是輸出結(jié)果不是能按順序,后臺返回。如果需要再排序下
復(fù)制代碼 代碼如下:
#!/bin/bash
#********************************#
#2013-01-11 17:00:00 wanggy exp #
#note:ping monitor #
#********************************#
set -u
ping_fun()
{
d_network=192.168.1
echo -n "input the network(default $d_network):"
read network
: ${network:=$d_network}
echo "network:$network"
d_hostip_beg=1
d_hostip_end=254
echo -n "input the 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++));do
{
host=$network.$hostip
echo "開始ping檢測$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 "----開始執(zhí)行ping程序----"
ping_fun
}
main
exit 0
相關(guān)文章
Linux服務(wù)器硬件運(yùn)行狀態(tài)及故障郵件提醒的監(jiān)控腳本分享
這篇文章主要介紹了Linux服務(wù)器硬件運(yùn)行狀態(tài)及故障郵件提醒的監(jiān)控腳本分享,能夠測試CPU和內(nèi)存的占用狀況以及HTTP端的異常,需要的朋友可以參考下2016-03-03Shell腳本創(chuàng)建指定大小文件的測試數(shù)據(jù)
這篇文章主要介紹了Shell腳本創(chuàng)建指定大小文件的測試數(shù)據(jù),本文同時給出使用DD命令和Shell腳本解決這個需求,給出的腳本功能更加強(qiáng)大,需要的朋友可以參考下2015-03-03