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循环。

  • 相关阅读:
    括号
    vue 框架原理
    Angular 1.x 框架原理
    ES5的数组方法
    js 对象细节
    《高性能网站建设进阶指南》笔记
    vue 运行时 + 编译器 vs. 只包含运行时
    vue-loader 细节
    vue 错误处理
    移动web touch事件
  • 原文地址:https://www.cnblogs.com/osxlinux/p/3517765.html
Copyright © 2011-2022 走看看