zoukankan      html  css  js  c++  java
  • expect远程登陆hw交换机--测试通过1

    #!/bin/bash
    #connect_the_hw_switch
    #by osx1260@163.com 
    
    
    swip=172.16.56.2
    swport=2081
    swpasswd='yourswpasswd'
    swusername=yourswusername
    time=$(date +"%F")
    echo ".............please wating 9s............"
    echo ".............This is $time..............."
    /usr/bin/expect -c "
    set timeout 3
    spawn  ssh $swip -l $swusername -p $swport
    
    expect "*(yes/no)? " { 
            send "yes
    "
            expect "password:
    "                               #这里如果是第一次登陆,判断yes/no
            send "$swpasswd
     "                   
    }
    
    
    expect "password:
    "
    send "$swpasswd
     "
    
    expect "*>
    "
    send "dis int g0/0/1 
     
    "
    #########################################
    #You cat input here like follow:
    #expect "*>
    "
    #send "dis int g0/0/1 
     
    "
    #########################################
    
    
    
    expect "*>
    "
    send "quit"
    
    "
    echo "Bye!!! "

    此脚本加入计划任务,作监控,可以将结果放入到其他文件。

    通过awk,sed等取出结果。

    或者新建一个脚本做while循环。

  • 相关阅读:
    软件工程二人组队开发第一周
    软件工程第五周
    这学期的目标
    软件工程第四周的总结
    二维数组的最大子数组和 时间复杂度:O(n的四次方)
    10.tesseract
    mysql存储过程和函数
    mysql触发器
    9.selenium
    mysql练习
  • 原文地址:https://www.cnblogs.com/osxlinux/p/3517765.html
Copyright © 2011-2022 走看看