一個shell寫的ping函數
更新時間:2013年02月04日 14:25:27 作者:
shell寫的ping腳本,可實現(xiàn)簡單交互,供大家學習參考吧
復制代碼 代碼如下:
#!/bin/bash
#2013-01-06 14:00:00 wanggy exp
#note:ping monitor
set -u
#set -x
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"
count=3
for ((hostip=$hostip_beg;hostip<=$hostip_end;hostip++));do
host=$network.$hostip
echo "開始ping檢測$host"
ping -c $count $host &>/dev/null
if [ $? = 0 ];then
echo "$host is up"
else
sleep 3
ping -c $count $host &>/dev/null
if [ $? = 0 ];then
echo "$host is up"
else
echo "$host is down"
fi
fi
done
#echo "執(zhí)行完畢"
exit 0
}
main()
{
echo "----開始執(zhí)行ping程序----"
ping_fun
}
main
exit 0
相關文章
Linux C中sockaddr和sockaddr_in的區(qū)別
這篇文章主要介紹了Linux C中sockaddr和sockaddr_in的區(qū)別的相關資料,需要的朋友可以參考下2017-07-07
Linux中使用locate和find進行不區(qū)分大小寫的文件搜索
在日常使用計算機的過程中,尤其是處理大量文件時,快速找到特定文件變得尤為重要,Linux系統(tǒng)提供了許多命令行工具,其中“l(fā)ocate”和“find”是兩個常用的文件搜索工具,本文給大家介紹了如何在Linux中使用locate和find進行不區(qū)分大小寫的文件搜索2024-05-05

