until自动网关切换

版权声明:本文为小胡子博主原创文章,转载请附上博文链接! https://blog.csdn.net/woshaguayi/article/details/90746843
#!/bin/bash
gw1=192.168.66.110
gw2=192.168.66.109
while :
do
  ip r del dafault
  ip r del dafault
  ip r add default via $gw1
  while ping -c1 $gw1 &>/dev/null
  do
    sleep 1
  done
   ip r del default
   ip r del default
   ip r add default via $gw2
   until ping -c1 $gw1& >/dev/null
   do 
    sleep 1
   done
done&

并行:

#!/bin/bash
#exec <>6 file打开文件file,并指定描述符为6
#exec 6<&- 关闭文件描述符6
#每个进程有一个数组记录打开的文件
#匿名管道
#命名管道  mkfifo 读取内容后管道文件的内容清空
thread=5
tmp=/tmp/$$.fifo
mkfifo $tmp
exec<>9 $tmp
rm $tmp
for i in `seq $thread`
do 
  echo >&9
done
for j in {1..254}
do
   read -u 9
   {
     ip=192.168.66.$j  
    ping $ip 
     if[ -eq 0 ];then
        echo "$ip is up"
     else
       echo "$ip is down"
      fi 
      echo >&9
    }&
done
wait
exec 9<&-

猜你喜欢

转载自blog.csdn.net/woshaguayi/article/details/90746843