Invoking an interactive bash script on top of ssh

I am writing a "tool" - a couple of bash scripts that automate the installation and configuration on each server in the cluster.

The "tool" works from the main server. It lifts up and distributes it independently (through SCP) to any other server and unpacks copies through "batch" SSH.

When setting up, the tool issues remote commands, for example, the following from the main server: echo './run_audit.sh' | ssh host4 'bash -s' echo './run_audit.sh' | ssh host4 'bash -s' . This approach works in many cases, except when there is interactive behavior, since standard input is already in use.

Is there a way to run remote bash scripts interactively via SSH?

As a starting point, consider the following case: echo 'read -p "enter name:" name; echo "your name is $name"' | ssh host4 'bash -s' echo 'read -p "enter name:" name; echo "your name is $name"' | ssh host4 'bash -s'

In the above example, the clue never happens, how do I get around this?

Thanks in advance.

+4
source share
3 answers

Run the command directly, for example:

 ssh -t host4 bash ./run_audit.sh 

For a rem, change the shell of the script so that it reads parameters from the command line or configuration file instead of stdin (or prefers stdin).

Dennis Williamson's second suggestion is to look at the puppet / etc.

+8
source

Looks like you can look at expect .

+1
source

Do not process commands via stdin for ssh, but copy the shell script to the remote machine:

 scp ./run_audit.sh host4: 

and then:

 ssh host4 run_audit.sh 

To deploy clusters I use Fabric ... it runs on top of the SSH protocol, no daemons are required. This is easy to write in the fabfile.py file:

 from fabric.api import run def host_type(): run('uname -s') 

and then:

 $ fab -H localhost,linuxbox host_type [localhost] run: uname -s [localhost] out: Darwin [linuxbox] run: uname -s [linuxbox] out: Linux Done. Disconnecting from localhost... done. Disconnecting from linuxbox... done. 

Of course, he can do more ... including interactive commands and relays in ~ / .ssh files for SSH. More details at fabfile.org . Surely you will forget bash for such tasks .; -)

0
source

All Articles