0

Use Case:

1> ssh into a machine -->using the expect script automation

2> Once ssh'ed into the machine run a script from my local machine onto the remote machine

Currently I'm doing the following approach:

ssh admin@128.34.56.127 < ./s4.sh
Pseudo-terminal will not be allocated because stdin is not a terminal.
admin@13.126.76.184's password: <Provide password>
<Script executes without any errors>

In the above scenario, I have to provide my password manually which is not the intended use case for automation.

So will be using the expect option which should help automate the login procedure.

Sample Code:

#!/usr/bin/expect -f
spawn ssh admin@128.34.56.127
expect "password"
send "password\r"

This code helps automate the login, but in the expect code... how will I give the command to trigger another script from inside my current script?

derHugo
  • 3,356
  • 5
  • 31
  • 51
  • Clarification: Are you looking for a efficient way to run a script (which is on your local machine) remotely, or are you trying to learn expect? Reason I am asking: Executing a script through SSH does not require expect (there are easier ways to do this). If you still wish to use expect, the tags should be adjusted. – sborsky Oct 21 '17 at 16:47

1 Answers1

0

In my opinion the entire approach could be improved:

  1. First you can use Key-Based SSH Login to securely authenticate yourself without password - just leave the passphrase empty when generate the key.

  2. Next you can create ~/.ssh/config file to ease the process of the creation of ssh connection.

  3. Then the automation script could execute just these steps:


  1. Alternatively you can mount a folder to the remote machine using sshfs and then just run the script remotely.
pa4080
  • 29,831