Expect 命令不适用于 Linux 中的代理链

Expect 命令不适用于 Linux 中的代理链

我正在使用 Expect 命令编写一个小脚本来提供密码;目的是登录交换机并获取命令。操作系统:RHEL 7。有一个小应用程序 proxychains,用于登录客户端网络。所以我需要先打开它,然后运行我的命令(ssh 等)。

例如:

[ram@abcde scripts]$ /usr/bin/proxychains ssh [email protected]
ProxyChains-3.1 (http://proxychains.sf.net)
|S-chain|-<>-129.39.159.150:1080-<>-138.222.124.15:1080-<><>-10.49.99.49:22-<><>-OK
[email protected]'s password: 

我想使用 Expect 来自动化上述操作,所以我有下面的脚本并出现错误。

set user "admin"
set password "sample123"
/usr/bin/proxychains ssh [email protected]
expect "ssword: "
send "$password\r"
expect ">\r"
send "switchshow\r"
expect eof

我遇到以下错误;

[ram@abcde scripts]$ sh br1.sh 
usage: ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
           [-D [bind_address:]port] [-E log_file] [-e escape_char]
           [-F configfile] [-I pkcs11] [-i identity_file]
           [-L [bind_address:]port:host:hostport] [-l login_name] [-m mac_spec]
           [-O ctl_cmd] [-o option] [-p port]
           [-Q cipher | cipher-auth | mac | kex | key]
           [-R [bind_address:]port:host:hostport] [-S ctl_path] [-W host:port]
           [-w local_tun[:remote_tun]] [user@]hostname [command]
br1.sh: line 3: ProxyChains-3.1: command not found
couldn't read file "ssword: ": no such file or directory
br1.sh: line 5: send: command not found
couldn't read file ">\r": no such file or directory
br1.sh: line 7: send: command not found
couldn't read file "eof": no such file or directory

答案1

将 SSHPASS 与 SSH 结合使用。句法:

sshpass -p 'password' ssh user@domain/ip "command"

相关内容