【问题标题】:write a script to spawn to R1(Router) and execute some commands on R1,and then you spawn to R2 and execute some commands on R1 again编写脚本生成到 R1(路由器)并在 R1 上执行一些命令,然后生成到 R2 并再次在 R1 上执行一些命令
【发布时间】:2014-06-12 00:50:34
【问题描述】:

我是新手,希望编写脚本,请任何人帮助解决这个问题。我知道如何连接到路由器 1,但如果添加了另一个路由器,则意味着如何连接到另一个路由器以及如何在它们上执行命令

【问题讨论】:

    标签: switch-statement expect spawn


    【解决方案1】:
    #!/usr/bin/expect
    set user "admin"
    set pwd "lab"
    
    set IP1 [lindex $argv 0] 
    set Cons1 [lindex $argv 1]
    set IP2 [lindex $argv 2]
    set Cons2 [lindex $argv 3]
    
    
    #Login to the first router
    spawn telnet $IP1 $Cons1
    set rtr1 $spawn_id  # Saving the spawn id into the variable 'rtr1'
    
    
    #Login to the first router
    spawn telnet $IP2 $Cons2
    set rtr2 $spawn_id # Saving the spawn id into the variable 'rtr2'
    
    
    expect -i $rtr1 "Login:" #This will expect 'Login' for the router 1
    expect -i $rtr2 "Login:" #This will expect 'Login' for the router 2
    send -i $rtr1 "$user\r" #This will send username to the router 1
    send -i $rtr2 "$user\r" #This will send username to the router 2
    expect -i $rtr1 "Password"
    expect -i $rtr2 "Password"
    send -i $rtr1 "$pass\r"
    send -i $rtr2 "$pass\r"
    expect -i $rtr1 -re ">"
    expect -i $rtr2 -re ">"
    
    
    #Do further operations
    

    请记住将每个sendexpect 操作的生成进程ID 变量以及-i 选项包括在内。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-08
      • 2012-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-06
      • 1970-01-01
      • 2015-05-29
      相关资源
      最近更新 更多