期望脚本 - bash 未找到脚本文件
Expect Script - bash script file not found
我的期望脚本
#!/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
P.S : 是的,文件存在且凭据正确。
Expect 脚本无法读取文件的内容,这就是问题所在。通过读取文件的内容并传递该变量而不是文件名来解决它,
set fh [open test.sh r]
set contents [read $fh]
close $fh
并将 sh-
替换为 bash -c '$contents'
谢谢大家的宝贵意见
我的期望脚本
#!/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
P.S : 是的,文件存在且凭据正确。
Expect 脚本无法读取文件的内容,这就是问题所在。通过读取文件的内容并传递该变量而不是文件名来解决它,
set fh [open test.sh r]
set contents [read $fh]
close $fh
并将 sh-
替换为 bash -c '$contents'
谢谢大家的宝贵意见