shell查看并修复网络连接
2016-11-14 11:40
274 查看
1. shell监控网卡状态,故障时自动重启网卡 http://blog.slogra.com/post-425.html
cat fix_eth0.sh
cat fix_eth0.sh
#!/bin/bash check_and_fix_eth0_link() { date="`date '+%Y-%m-%d %H:%M:%S'`" # step3 : if have ip, ping $dns lost_rate=`ping -c 8 -w 8 $dns -I $eth0 | grep 'packet loss' \ | awk -F'packet loss' '{ print $1 }' \ | awk '{ print $NF }' | sed 's/%//g'` # step4: if ping dns failed, fix the link of $eth0 if [ $lost_rate -eq 0 ] then echo "network_ok $date $dns $dev" >>/root/network_ok.log elif [ $lost_rate -le 100 ] then echo "network_error $date $dns $dev" >>/root/network_error.log ifconfig $usb0 down sleep 1 ifconfig $usb0 up fi } eth0="eth0" usb0="usb0" dns="61.139.2.69" touch /root/network_ok.log touch /root/network_error.log while [ 1 ] do # step 1 : test if $eth0 have ip ipaddr=` /sbin/ifconfig $eth0 | grep "inet addr" | awk '{ print $2}' | awk -F: '{print $2}' ` if [ ! -n "$ipaddr" ] then # step2 : if have no ip, reset the $eth0, maybe the "udhcpc -i $eth0 ?" echo " $0: NO IP Addr" /etc/init.d/networking restart else check_and_fix_eth0_link; fi sleep 10 done
相关文章推荐
- 允许生成core;查看网络连接
- netstat命令------查看网络连接状态
- netstat查看linux服务器网络连接状态
- 查看linux网络连接,连接总数
- netstat 命令查看本机网络连接情况
- 快速修复Vista不能连接网络问题
- 查看Linux网络连接及连接总数
- 查看网络连接
- 修复网络打印机/网络共享无法连接的问题
- 查看网络连接 需要经过的中间点
- DNS修复,模拟修复网络连接(原)
- netstat查看linux服务器网络连接状态
- linux下查看网络连接
- linux 常用查看网络连接方法及脚本
- 检查IP配置来修复Windows网络连接
- 查看“网络连接”时“出现意外错误”的解决办法
- 查看不到网络连接(可以上网)
- 查看Linux网络连接及连接总数
- 实时查看网络流量的shell脚本
- Windows2003无法看到网络连接,修复COM+组件