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.

4
  • How would you authenticate with neither the public key not the password?
    – jobin
    Mar 25, 2014 at 13:02
  • @Jobin The password is being sent by the expect script above.
    – Oli
    Mar 25, 2014 at 13:13
  • I hope you are aware that this is much less safe than using a public key. Just in case you were doing this for security.
    – terdon
    Mar 25, 2014 at 15:06
  • Hi terdon, I know this is less secure. But I need this in my scenario. Mar 27, 2014 at 6:48

1 Answer 1

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'"
3
  • bah, there are quoting issues there ("there be dragons..."). Let us know how you get on. Mar 25, 2014 at 13:35
  • Your approach here might be a better one: stackoverflow.com/a/14044575/12870
    – Oli
    Mar 26, 2014 at 8:58
  • Hi glenn, now it just displays the external script while running this. Mar 27, 2014 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.