I have a bash script which loops over a server list, runs a couple of remote commands via SSH, and writes the output of those commands to a local file. For every command I run on the remote server I open a new SSH session. Is there a way that only one SSH session remains open to a server, and that I can run multiple commands which the output I can redirect to a local file?
|
feedback
|
|
You want to look into the | |||||||
feedback
|
|
Note: When you say local file, I am not sure if you mean local the machine you just ssh'd into, or if you mean local to the machine the starts the ssh session. Push vs Pull: Run Multiple Commands:
You can also do stuff like the following if you want to specify use of things in a shell:
Lastly, you could always just put the script on each server, and just run that. | ||||
|
feedback
|
|
You can run several commmands in sequence by starting a shell on the remote system and passing it the commands:
will automatically pass the quoted string through a remote shell. Beware of shell quoting rules, though! | |||
|
feedback
|
|
The "expect" tool could also do what you want, but involves writing tcl. | |||
|
feedback
|
|
To expand on the ControlMaster use, here's a slightly more concrete example:
This is largely untested, but it should give you the right general idea. | |||
|
feedback
|