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?
Linux – Retaining SSH session in bash script
bashlinuxscriptingssh
Related Topic
- SSH not seeming to run in bash script called via web server
- Bash – Run an interactive bash subshell with initial commands without returning to the (“super”) shell immediately
- Linux – SSH – set env vairables by every connection – godaddy shared host
- Ssh – Remote bash script execution via ssh causes local script to stop
- Linux – Use bash script to send commands to SSH client
Best Answer
You want to look into the
ControlMaster
setting for SSH. That allows you to create a single SSH connection and then have all the other SSH connections to the same server multiplex over that one connection. Very handy.