期待 ssh 脚本(在远程机器上执行命令)
Expect ssh script (execute command on remote machine)
我正在编写一个使用 ssh 在远程服务器上执行命令的 expect 脚本。
命令语法:ssh <classname> <command>
代码:
set ip "hive28.cs.berkeley.edu"
set class [lindex $argv 0]
// set $user and $ip according to class
set cmd [lindex $argv 1]
spawn ssh "$user\@$ip '$cmd'"
expect "assword"
send "$password\r";
interact
不幸的是,我得到这个错误:
~/foo> ssh2 162 'pwd'
spawn ssh ***@hive28.cs.berkeley.edu 'pwd'
ssh: Could not resolve hostname hive28.cs.berkeley.edu 'pwd': Name or service not known
send: spawn id exp6 not open
while executing
"send "$password\r""
invoked from within <...>
但是当我 运行 直接生成命令时,它起作用了(忽略 gdircolors
警告):
~/foo> ssh ***@hive28.cs.berkeley.edu 'pwd'
***@hive28.cs.berkeley.edu's password:
/home/ff/cs162/adm/bashrc.d/70-gnu.sh: line 36: gdircolors: command not found
/home/cc/cs162/sp16/class/***
试试这个:
set ip "hive28.cs.berkeley.edu"
set class [lindex $argv 0]
set cmd [lindex $argv 1]
spawn ssh "$user@$ip" "$cmd"
expect "assword"
send "$password\r";
interact
问题似乎出在你的引用上。 "$user\@$ip"
和 "$cmd"
是两个独立的参数。
我正在编写一个使用 ssh 在远程服务器上执行命令的 expect 脚本。
命令语法:ssh <classname> <command>
代码:
set ip "hive28.cs.berkeley.edu"
set class [lindex $argv 0]
// set $user and $ip according to class
set cmd [lindex $argv 1]
spawn ssh "$user\@$ip '$cmd'"
expect "assword"
send "$password\r";
interact
不幸的是,我得到这个错误:
~/foo> ssh2 162 'pwd'
spawn ssh ***@hive28.cs.berkeley.edu 'pwd'
ssh: Could not resolve hostname hive28.cs.berkeley.edu 'pwd': Name or service not known
send: spawn id exp6 not open
while executing
"send "$password\r""
invoked from within <...>
但是当我 运行 直接生成命令时,它起作用了(忽略 gdircolors
警告):
~/foo> ssh ***@hive28.cs.berkeley.edu 'pwd'
***@hive28.cs.berkeley.edu's password:
/home/ff/cs162/adm/bashrc.d/70-gnu.sh: line 36: gdircolors: command not found
/home/cc/cs162/sp16/class/***
试试这个:
set ip "hive28.cs.berkeley.edu"
set class [lindex $argv 0]
set cmd [lindex $argv 1]
spawn ssh "$user@$ip" "$cmd"
expect "assword"
send "$password\r";
interact
问题似乎出在你的引用上。 "$user\@$ip"
和 "$cmd"
是两个独立的参数。