Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

calling an interactive bash script over ssh

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.

like image 760
Mario Aguilera Avatar asked Jul 07 '12 06:07

Mario Aguilera


People also ask

How do I run a shell script in interactive mode?

You run the shell script (pure. bat on Windows and pure on Linux®) from the pure. cli/bin directory on your local computer. In this procedure you start in interactive mode, specifying the host name or IP address for the system, along with an authorized user ID and password to start a user session.

Can I SSH in a bash script?

Bash script SSH is a common tool for Linux users. It is needed when you want to run a command from a local server or a Linux workstation. SSH is also used to access local Bash scripts from a local or remote server.

How do you call a bash script from anywhere?

In order to run a Bash script from anywhere on your system, you need to add your script to your PATH environment variable. Now that the path to the script is added to PATH, you can call it from where you want on your system. $ script This is the output from script!


2 Answers

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.

like image 120
dave4420 Avatar answered Sep 28 '22 16:09

dave4420


Sounds like you might want to look into expect.

like image 39
Amber Avatar answered Sep 28 '22 14:09

Amber