1

I have local shell script. Now, I want to run this local script in remote machine. Of course I can use ssh, but as it(the local shell script) should be like an automated one, it shouldn't ask for password to enter manually. So I used expect to eliminate that problem, so that if I run the script it wont ask password. And my script looks like below.

#!/usr/bin/expect
spawn ssh -o GSSAPIAuthentication=no root@10.3.0.39 'bash -s' < /path/to/localscript
expect -timeout 7 "*(yes/no)?" { send "yes\r";exp_continue } 
expect -timeout 3 "*d: "
send "qbcrootpass\n"
interact

But it is not working. Please note, in my scenario, I don't want to use public key authentication.

Please help me to execute a local script in a remote machine using using expect.

1 Answers1

2

That redirection is processed by your shell at the command line. Expect won't understand how to do it. This should work (untested):

set fh [open /path/to/localscript r]
set contents [read $fh]
close $fh

spawn ssh ... "bash -c '$contents'"
glenn jackman
  • 18,218