Skip to content

Execute Script Over SSH via a Jumpbox #51

@trevrobwhite

Description

@trevrobwhite

Hi @merlinthemagic
Your repo looks fantastic just what I need, but I was after some help. (I wasn't sure if to post here or in MTM-SSH, sorry if it's wrong)

My problem, I need to run a script (Bash, Perl, etc) on a remote machine but I can only access it via a Jumpbox over SSH using Key authentication.
A <-> B <-> C

ServerA contains the script and the key to access ServerB, need to connect as nagios
ServerB contains the key to connect to server ServerC, need to connect as root

PHP is version 7.0, running on Ubuntu 16.04 LTS, OpenSSH_7.2p2 Ubuntu-4ubuntu2.1 (Sadly no -J support)

As of today, I'm limited to a one liner via SSH and quotes are always a problem, as mentioned I would ideally like to create a PHP script which reads the contents on the script file and is able to execute them directly on ServerC, capturing the output (and return code if possible) without the need for multiple SCP/temporary files.

ssh -q -o BatchMode=yes -o StrictHostKeyChecking=no -o ConnectTimeout=10 -t nagios@ServerB ssh -q -o BatchMode=yes -o StrictHostKeyChecking=no -o ConnectTimeout=5 root@ServerC 'command'

Thanks in advance.

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions