在expect脚本中运行bash脚本

时间:2016-08-20 04:12:48

标签: linux bash unix expect

我试图在期望脚本中运行我的bash脚本但是收到错误。

s.listen(5)
(client, address) = s.accept()
print(address, 'just connected!')

while True:
    message = raw_input("Would you like to close the connection? (y/n)")

我试图在期待/usr/bin/expect <<EOD spawn ssh nginubud@10.123.25.83 $(< try1.sh) expect "assword:" send "$reg\r" expect eof EOD 中执行此操作,这个正在运行,但我需要找到一种以自动方式运行它的方法。我不想使用RSA密钥。

遇到的错误:

ssh nginubud@10.123.25.83 "$(< try1.sh)"

此外,我可以运行我期望的ssh脚本但是当我包含并尝试运行我的spawn ssh nginubud@10.123.25.83 #tats script invalid command name "echo" while executing "echo "Enter Year:"" 我正在获取&#34;没有变量错误&#34;

1 个答案:

答案 0 :(得分:0)

您可以使用ssh user@host bash -c ...。例如:

[bash] % cat foo.sh
export CMD=$( printf '%q' "$(< try.sh)" )
expect << EOF
spawn ssh foo@localhost bash -c \$::env(CMD)
expect -nocase password:
send bar\r
expect eof
EOF
[bash] % cat try.sh
echo hello world | tr a-z A-Z
[bash] % bash foo.sh
spawn ssh foo@localhost bash -c echo\ hello\ world\ \|\ tr\ a-z\ A-Z
foo@localhost's password:
HELLO WORLD
[bash] %