我正在尝试通过ActiveState TCL 'tclsh‘窗口中的.tcl脚本进行ssh。有WINDOWS操作系统。
#!/bin/sh
# \
exec tclsh "$0" ${1+"$@"}
package require Expect
set user [lindex $argv 0]
set password [lindex $argv 1]
set DeviceIpAddr [lindex $argv 2]
set DeviceHostName [lindex $argv 3]
foreach DeviceIp $DeviceIpAddr HostName $DeviceHostName {
spawn ssh $DeviceIp
expect "login as:"
send "$user\r"
expect "Password:"
send "$password\r"
expect "$HostName ~]#"
} 在tclsh(ActiveTCL)中执行时,我看到以下错误
% tclsh Test.tcl root 321 17.250.217.151 lb02va
The system cannot find the file specified.
while executing
"spawn ssh root@$DeviceIp"
("foreach" body line 3)
invoked from within
"foreach DeviceIp $DeviceIpAddr HostName $DeviceHostName {
spawn ssh root@$DeviceIp
expect "login as:"
send "$user\r"
expect "Password:"
send..."
(file "Test.tcl" line 12)
child process exited abnormally 请帮助我解决这个问题。谢谢。
发布于 2015-05-10 13:49:31
首先,确保您已经安装了ssh。在bash提示符(Mac、Linux、Cygwin)或cmd提示符(Windows)中,键入:
ssh如果您看到错误,请尝试修复它。最可能的原因是ssh没有安装,或者没有在路径中。
接下来,在脚本中,您没有使用$user变量,而是使用了硬编码的root。解决这个问题:
spawn ssh $user@$DeviceIp最后一个问题:您已经从命令行指定了用户名,ssh程序不会再次询问user,因此您必须删除这两行:
expect "login as:"
send "$user\r" 在那之后,希望一切都能按计划进行。
https://stackoverflow.com/questions/30122449
复制相似问题