0

I have a remote SSH server with several custom utilities for my work. However, there are times when I feel lazy and don't want to start a full SSH session just to execute a single command.

This motivated me to create a multi-call script à la BusyBox that I could make symlinks to which would look at the name it was called with and run the matching command on my server and forward any arguments I give it.

I came up with this first:

#!/bin/bash

exec ssh -q -t my-server "$(basename "$0")" "${@@Q}"

but that doesn't set my PATH correctly, so I can't use all my programs.

Next, I tried going through bash as a login shell:

exec ssh -q -t my-server bash -l "$(basename "$0")" "${@@Q}"

but I got an error like this whenever I ran something that isn't a bash script:

/bin/ls: /bin/ls: cannot execute binary file

I tried passing a command string to bash:

exec ssh -q -t my-server bash -l -c "$(basename "$0")" "${@@Q}"

This properly sets the PATH and executes binaries, but any arguments I pass to the binary are lost.

I tried to pass in the arguments as a herestring:

exec ssh -q -t my-server bash -l <<< "$(basename "$0") ${*@Q}"

but interactive programs close immediately.

Is what I want to do possible? How can I run an arbitrary remote command over SSH that is not on the standard PATH and make it act like I'm logged in normally?

2

1 Answer 1

0

It looks like I needed to add another level of escaped quotes to make bash run the command properly. So far, this works exactly as I want it to.

#!/bin/bash

exec ssh -q -t eng-vm bash -l -c \""$(basename "$0") ${*@Q}"\"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .