简体   繁体   中英

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; it fails.

This is the output if I execute it via the expect script. 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.

Expect script was unable to read the contents of the file, that was the issue. 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'

Thank you everyone for the valuable comments.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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