I have a shell script that connects via SSH to the same host (my-server) and runs a variety of commands mixed throughout the script. For example:
ssh -o ConnectTimeout=3 -o ConnectionAttempts=3 user@my-server "foocommand here"
mkdir -p /path/here
touch service.conf
...
ssh -o ConnectTimeout=3 -o ConnectionAttempts=3 user@my-server "barcommand here"
mkdir -p /other/path/here
touch /other/path/here/service.conf
...
ssh -o ConnectTimeout=3 -o ConnectionAttempts=3 user@my-server "darcommand here"
And so forth. The problem is each SSH connection open and handshake takes a bit of time as the server my-server
is geographically far away from the running script.
Is there a way to speed up this process and prevent opening a new SSH connection for each required command? Anything like http keep alive for SSH?