一個(gè)shell寫的ping函數(shù)
更新時(shí)間:2013年02月04日 14:25:27 作者:
shell寫的ping腳本,可實(shí)現(xiàn)簡(jiǎn)單交互,供大家學(xué)習(xí)參考吧
復(fù)制代碼 代碼如下:
#!/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檢測(cè)$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
相關(guān)文章
簡(jiǎn)介L(zhǎng)inux中cp和mv搭配{,}在shell當(dāng)中的用法
這篇文章主要介紹了簡(jiǎn)介L(zhǎng)inux中cp和mv搭配{,}在shell當(dāng)中的用法,作者舉了四個(gè)這樣的大括號(hào)擴(kuò)展示例,需要的朋友可以參考下2015-06-06
Linux Shell 自動(dòng)交互功能實(shí)現(xiàn)
本文主要介紹了Linux Shell 自動(dòng)交互功能實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-08-08
Linux C中sockaddr和sockaddr_in的區(qū)別
這篇文章主要介紹了Linux C中sockaddr和sockaddr_in的區(qū)別的相關(guān)資料,需要的朋友可以參考下2017-07-07
Linux中使用locate和find進(jìn)行不區(qū)分大小寫的文件搜索
在日常使用計(jì)算機(jī)的過程中,尤其是處理大量文件時(shí),快速找到特定文件變得尤為重要,Linux系統(tǒng)提供了許多命令行工具,其中“l(fā)ocate”和“find”是兩個(gè)常用的文件搜索工具,本文給大家介紹了如何在Linux中使用locate和find進(jìn)行不區(qū)分大小寫的文件搜索2024-05-05

