shell實(shí)現(xiàn)自動(dòng)adsl撥號(hào)并檢測(cè)連接狀況腳本分享
今天公司同事要我整個(gè)adsl自動(dòng)重?fù)艿膕hell,并檢測(cè)是否連上了,這樣才能保證內(nèi)部測(cè)試服務(wù)器不掉網(wǎng),好吧,下面我把腳本發(fā)出來(lái).
系統(tǒng):centos 5.x
腳本1:
cat /root/soft_shell/auto_adsl_1.sh
#!/bin/bash
gateway=`ifconfig ppp0 |grep P-t-P| cut -f 3 -d ":"|cut -f 1 -d " "`
inter=`ifconfig |grep ppp0|awk '{print $1}'`
N=2
if [[ $inter -eq ppp0 ]]
then
/sbin/adsl-stop
sleep 10
/sbin/adsl-start
sleep 20
pkgloss=`ping -c4 $gateway|grep 'transm' |awk -F',' '{print $2}' |awk '{print $1}'`
if [[ $pkgloss -lt $N ]]
then
echo "`date +%Y-%m-%d/%T` The network is not stable">>/root/adsl.txt
else
echo "`date +%Y-%m-%d/%T` The network is normal">>/root/adsl.txt
fi
fi
腳本2:
cat /root/soft_shell/auto_adsl_2.sh
#!/bin/bash
gateway=`ifconfig ppp0 |grep P-t-P| cut -f 3 -d ":"|cut -f 1 -d " "`
inter=`ifconfig |grep ppp0|awk '{print $1}'`
N=2
if [[ $inter != ppp0 ]]
then
/sbin/adsl-start
sleep 20
pkgloss=`ping -c4 $gateway|grep 'transm' |awk -F',' '{print $2}' |awk '{print $1}'`
if [[ $pkgloss -lt $N ]]
then
echo "`date +%Y-%m-%d/%T` The network is not stable">>/root/adsl.txt
else
echo "`date +%Y-%m-%d/%T` The network is normal">>/root/adsl.txt
fi
fi
ps:腳本2的作用就是檢測(cè)adsl撥號(hào)是否有連上.
相關(guān)文章
crontab每10秒執(zhí)行一次的實(shí)現(xiàn)方法
下面小編就為大家?guī)?lái)一篇crontab每10秒執(zhí)行一次的實(shí)現(xiàn)方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-04-04shell腳本實(shí)現(xiàn)的網(wǎng)站日志分析統(tǒng)計(jì)(可以統(tǒng)計(jì)9種數(shù)據(jù))
這篇文章主要介紹了shell腳本實(shí)現(xiàn)的網(wǎng)站日志分析統(tǒng)計(jì),可以統(tǒng)計(jì)9種數(shù)據(jù),如訪(fǎng)問(wèn)量、帶寬、訪(fǎng)客量、IP統(tǒng)計(jì)、搜索引擎等,需要的朋友可以參考下2014-05-05linux 獲取某個(gè)日期對(duì)應(yīng)的月末日期方法
今天小編就為大家分享一篇linux 獲取某個(gè)日期對(duì)應(yīng)的月末日期方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-06-06shell腳本運(yùn)行5秒后自動(dòng)退出的代碼
shell腳本運(yùn)行5秒自動(dòng)退出的代碼,供大家學(xué)習(xí)參考2013-02-02