My expect script#!/usr/bin/expect -f#I tried replacing sh - with bash -s still no positive resultsspawn ssh xxxx@yyyy sh - < test.shexpect password: send zzzzz\rexpect $ This command works well if executed in the terminalssh xxxx@yyyy sh - < test.shBut 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 wrongbash: test.sh: No such file or directoryP.S : Yes, the file exists and the credentials are right.
Expect Script - bash script file not found
bash;macintosh;expect
The problem is that the redirection with < is being done locally when you run ssh on its own (by the shell you are typing into), but being done on the remote machine when you run from expect, because spawn simply copies the arguments you provide, so the < is passed to the remote as part of the ssh command. It is as if you typed 'ssh' 'xxxx@yyyy' sh - '<' 'test.sh' to the shell, which similarly will not work.You need to add an intermediate shell command to get the redirection parsed before the ssh. Use for example, spawn sh -c ssh xxxx@yyyy sh - < test.sh