calling an interactive bash script over ssh

Mario Aguilera picture Mario Aguilera · Jul 7, 2012 · Viewed 7k times · Source

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

The "tool" runs from a primary server. It tars and distributes it's self (via SCP) to every other server and untars the copies via "batch" SSH.

During set-up the tool issues remote commands such as the following from the primary server: echo './run_audit.sh' | ssh host4 'bash -s'. The approach works in many cases, except when there's interactive behavior since standard input is already in use.

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

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

In the case above the prompt never happens, how do I work around that?

Thanks in advance.

Answer

dave4420 picture dave4420 · Jul 7, 2012

Run the command directly, like so:

ssh -t host4 bash ./run_audit.sh

For an encore, modify the shell script so it reads options from the command line or a configuration file instead of from stdin (or in preference to stdin).

I second Dennis Williamson's suggestion to look into puppet/etc instead.