我试图在期望脚本中运行我的bash脚本,但出现错误。
/usr/bin/expect <<EOD
spawn ssh [email protected] $(< try1.sh)
expect "assword:"
send "$reg\r"
expect eof
EOD
我试图在期望做到这一点ssh [email protected] "$(< try1.sh)"
,这是工作,但我需要找到一种以自动化方式运行它的方法。我不想使用RSA密钥。
遇到的错误:
spawn ssh [email protected] #tats script
invalid command name "echo"
while executing
"echo "Enter Year:""
我也可以运行我期望的ssh脚本,但是当我包含并尝试运行我的$(< try1.sh)
即时消息时,“无变量错误”
您可以使用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] %
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句