Tcl 多次使用expect生成会话

Tcl 多次使用expect生成会话,tcl,expect,Tcl,Expect,我只想为通过ssh连接到多个设备(有时是三个设备,有时是十个设备,…)编写一个脚本,并在其中执行相同的命令 例如: 如果执行/script.sh ipaddress1 ipaddress2 ipaddress5 我想对所有设备(ipaddress 1、2和5)执行一个ssh,以执行一个命令并关闭会话。但我的问题是,只有我能连接到第一台设备。在连接到最后一个设备之前,如何执行一个循环 #!/usr/bin/expect -f set list_ip [lindex $argv 0] forea

我只想为通过ssh连接到多个设备(有时是三个设备,有时是十个设备,…)编写一个脚本,并在其中执行相同的命令

例如: 如果执行
/script.sh ipaddress1 ipaddress2 ipaddress5
我想对所有设备(ipaddress 1、2和5)执行一个ssh,以执行一个命令并关闭会话。但我的问题是,只有我能连接到第一台设备。在连接到最后一个设备之前,如何执行一个循环

#!/usr/bin/expect -f

set list_ip [lindex $argv 0]

foreach ip $list_ip {
spawn ssh -l NA $ip
  expect "password:"
  send "pepe\n"
  expect "#"
  exp_send "sh linecard all\n\r"
  send "\n"
  send "exit\n"
  send "\n"

expect eof
}
expect "%"

嗯,很简单。浏览
argv
列表(所有参数),而不是第一个参数:

#!/usr/bin/expect -f
foreach ip $argv {
    spawn ssh -l NA $ip
    expect "password:"
    send "pepe\n"
    expect "#"
    exp_send "sh linecard all\n\r"
    send "\n"
    send "exit\n"
    send "\n"

    expect eof
}