无法在 ActiveTCL 中使用 TCL 生成 ssh [英] unable to spawn ssh using TCL expect in ActiveTCL

查看:44
本文介绍了无法在 ActiveTCL 中使用 TCL 生成 ssh的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 ActiveState TCL 'tclsh' 窗口通过 .tcl 脚本 ssh.有WINDOWS操作系统.

I am trying to ssh through .tcl script from ActiveState TCL 'tclsh' window. Having WINDOWS OS system.

#!/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) 中执行时看到以下错误

I see below error while execute in 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    

请帮助我解决这个问题.谢谢.

Kindly assist me resolving this. Thank you.

推荐答案

首先,请确保您已安装 ssh.在 bash 提示符(Mac、Linux、Cygwin)或 cmd 提示符 (Windows) 中,键入:

First, make sure that you have ssh installed. From the bash prompt (Mac, Linux, Cygwin) or cmd prompt (Windows), type:

ssh

如果您看到错误,请尝试修复它.最可能的原因是ssh没有安装,或者不在路径中.

If you see an error, try to fix it. The most likely cause is ssh not installed, or not in the path.

接下来,在您的脚本中,您没有使用 $user 变量,而是使用了硬编码的 root.解决这个问题:

Next, in your script, you did not use the $user variable, instead you use the hard-coded root. Fix that:

spawn ssh $user@$DeviceIp

最后一个问题:你已经在命令行指定了用户名,ssh程序不会再请求用户,所以你必须删除这两行:

The final problem: you already specified the user name from the command line, the ssh program will not ask for user again, so you must delete these two lines:

expect "login as:"    
send "$user\r"    

在那之后,希望一切都会按计划进行.

After that, hopefully everything will go as planned.

这篇关于无法在 ActiveTCL 中使用 TCL 生成 ssh的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆