lucia1112 2011-12-07 20:17 采纳率: 0%
浏览 266
已采纳

expect登录交换机脚本

写了段登录交换机的脚本,进行用户名和密码的判断,怎么这么写登录不上去啊
正常应该是:
telnet 200.2.0.3
登录后提示'>',输入'en',提示'Password:'输入密码,如果密码正确则得到提示'#'
用下面代码不能实现正常登录交换机,即时密码修改正确,请问如何修改

spawn telnet "200.2.0.3 23"
expect {
"name:" {
send "a\r"
expect "word:"
}
">" {
send "en\r"
expect "word:"
}
"word" {
send "a\r"
}
}
expect "#"

  • 写回答

1条回答 默认 最新

  • iteye_1007 2011-12-09 16:33
    关注

    这个和telnet登录的系统版本有关,可以手动登录确定各阶段的标志符, 下面是SSH登录例子,希望对你有参考价值。
    [code="shell"]#!/usr/bin/expect
    set timeout 5
    set username [lindex $argv 0]
    set hostip [lindex $argv 1]
    set passwd [lindex $argv 2]
    set cmdfile [lindex $argv 3]
    spawn ssh $username@$hostip
    expect {
    "yes/no" {send "yes\n"}
    }
    expect {
    "password:" {send "$passwd\n"}
    "Password:" {send "$passwd\n"}
    }
    set f [open $cmdfile]
    while {[gets $f line]>=0} {

    expect {
    "*#" {send "$line\n"}
    "*$ " {send "$line\n"}
    "*]" {send "$line\n"}
    "*: " {send "$line\n"}
    "*> " {send "$line\n"}
    "*>" {send "$line\n"}
    }
    }
    close $f
    expect "#"
    send "quit\n"
    expect eof
    exit
    [/code]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示