Zend certified PHP/Magento developer

Execute remote command

I use autossh to keep a connection open to a remote mysql server. autossh -p 22 -M 0 -L 33061:localhost:3306 root@10.0.0.101 -f -C -N

Basically, whenever I type: mysql -h localhost -P33061 I access mysql server on the remote mysql server.

Now, I would like to have another connection open to another server and would like to execute certain commands on the remote server. How do I do this?

The only workaround I found is to always

connect to remote server
execute command on remote server
disconnect from remote server.

I do this via a similar command: ssh root@10.0.0.2 -p 22 “ls”

The problem with this approach is that it always connect first, execute the command then disconnect. And this takes time. I want to keep the connection always open and execute from shell commands from the remote machine.

So, I should autossh to remote, autossh will keep the connection open and I would need the correct way to execute the “ls” command on remote server (returning the result locally).

What’s the best way to achieve this?