脚本执行交换机命令

一、交换机

1、检测网络状态,正常输出OK,异常自动登录交换机执行预定好的配置命令

[root@localhost ~]# cat sw.sh 
#!/bin/bash
 
#Network Checking script
 
iplist="114.114.114.114"
 
for ip in $iplist
 
do
 
  if ping -I ens33 -c 20 $ip >iplog.txt;cat iplog.txt | grep -w '0% packet loss'

  then
 
      rm -f iplog.txt
 
      echo $ip line is ok 
 
  elif
 
     cat iplog.txt | grep -w '100% packet loss'
 
  then
 
      /root/huawei.sh
 
 
  fi
 
done

二、Centos7 

1、安装expect

yum install -y expect

2、异常切换交换机静态路由(不需要super切换用户)

[root@localhost ~]# cat huawei.sh 
#!/bin/expect
 
set timeout 30
set host "192.168.88.2"
set username "admin"
set password "交换机登录密码"
 
spawn ssh $username@$host
expect "*password*" {send "$password\r"}
expect "*>" {send "system-view\r"}
expect "*]" {send "ip route

你可能感兴趣的:(网络运维,linux,expect,交换机脚本)