我的期望脚本
#!/usr/bin/expect -f
#I tried replacing sh - with bash -s still no positive results
spawn ssh xxxx@yyyy "sh -" < test.sh
expect "password: "
send "zzzzz\r"
expect "$ "
如果在终端中执行此命令,则效果很好
ssh xxxx@yyyy "sh -" < test.sh
但是,如果我通过expect
脚本执行它;它失败。
如果我通过Expect脚本执行它,则为输出。我可以知道我要去哪里了吗
bash: test.sh: No such file or directory
PS:是的,该文件存在并且凭据正确。
问题是,<
当您单独运行ssh时(通过您键入的shell),重定向是在本地完成的,而从运行时,则是在远程计算机上完成的expect
,因为spawn
只需复制您提供的参数,因此<
作为ssh命令的一部分传递给远程服务器。就像您'ssh' 'xxxx@yyyy' "sh -" '<' 'test.sh'
在shell上键入一样,这同样行不通。
您需要添加一个中间shell命令以在ssh之前解析重定向。举例来说,
spawn sh -c "ssh xxxx@yyyy sh - < test.sh"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句