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 [email protected] < ./s4.sh
Pseudo-terminal will not be allocated because stdin is not a terminal.
[email protected]'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 [email protected]
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?

1
  • 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, 2017 at 16:47

1 Answer 1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .