shell实现自动adsl拨号并检测连接状况脚本分享
今天公司同事要我整个adsl自动重拨的shell,并检测是否连上了,这样才能保证内部测试服务器不掉网,好吧,下面我把脚本发出来.
系统: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的作用就是检测adsl拨号是否有连上.
shell中嵌套执行expect命令实例
一直都想把expect的操作写到bash脚本里,这样就不用我再写两个脚本来执行了,搞了一下午终于有点小成就,给大家看看吧.系统:centos5.x1.先安装expectyum-yinstall
Shell根据web日志计算平均连接时间功能
今天在网上看到一个求web连接平均时间的shell命令,在自己的机器上试了下,发现不能使用,居然出现awk:fatal:divisionbyzeroattempted这样的错误,毛了就自己改了
Shell编程指南
基础知识shell执行方式shxx.sh(文件须有r权限)||./xx.sh(文件须有x权限)注:shxx.sh方式比较安全文件名后缀.shshell内容开头#!/bin/bash||#!/bin/sh||#!/bin/csh||#!/bin/
标签:脚本,连上,自己的,命令,平均