1

我遇到了它一直退出的问题,我只是想不通为什么它不能再放入期望任何发送语句来保持 SSH 会话继续进行???

#!/usr/bin/expect
set timeout 15
set hostname [lindex $argv 0]
set username [lindex $argv 1]
set password [lindex $argv 2]
set enable [lindex $argv 3]
set send_slow {10 .001}
log_user 1

expect -f snmp2.exp 172.28.135.24 localadmin Gr0upM540 z540Mxy3
set configuration /tmp/ntp
set routerlist [open "/tmp/routerlist" "r"]
set logfile [open "/tmp/ntp_config" "w"]


spawn ssh $username@$hostname

expect {
  timeout { send_user "\nFailed to get password prompt\n"; exit 1 }
  eof { send_user "\nSSH failure for $hostname\n"; exit 1 }
  "*#" {}
  "*assword:" {
    send "$password\r"
  }
}

send "/r"

expect {
  "*#" {}
  "*>" {
    send "enable\r"
    expect "*assword"
    send "$enable\r"
    expect "*#"
  }
}

send "exit\r"
send_user "\nSuccessfully changed SNMP password on $hostname\n"
close
4

0 回答 0