简体   繁体   English

期待脚本 - 找不到bash脚本文件

[英]Expect Script - bash script file not found

My expect script 我期待脚本

#!/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 "$ "

This command works well if executed in the terminal 如果在终端中执行,该命令运行良好

ssh xxxx@yyyy "sh -" < test.sh

But if I execute it via expect script; 但是如果我通过expect脚本执行它; it fails. 它失败。

This is the output if I execute it via the expect script. 如果我通过expect脚本执行它,那么这是输出。 May I know where I am going wrong 我可以知道我哪里错了

bash: test.sh: No such file or directory

PS : Yes, the file exists and the credentials are right. PS:是的,文件存在且凭据正确。

Expect script was unable to read the contents of the file, that was the issue. Expect脚本无法读取文件的内容,这就是问题所在。 Solved it by reading the contents of the file and passing that variable instead of the file name, 通过读取文件的内容并传递该变量而不是文件名来解决它,

set fh [open test.sh r]
set contents [read $fh]
close $fh

and replacing the sh- with bash -c '$contents' 并用bash -c '$contents'替换sh-

Thank you everyone for the valuable comments. 谢谢大家的宝贵意见。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM