SSH RPC (transparently run command on remote host)

echo -e '#!/bin/bash\nssh remote-user@remote-host $0 "$@"' >> /usr/local/bin/ssh-rpc; chmod +x /usr/local/bin/ssh-rpc; ln -s hostname /usr/local/bin/ssh-rpc; hostname
It's useful mostly for your custom scripts, which running on specific host and tired on ssh'ing every time when you need one simple command (i use it for update remote apt repository, when new package have to be downloaded from another host). Don't forget to set up authorization by keys, for maximum comfort.
Sample Output
# before 
# after

By: mechmind
2011-12-28 17:43:34

What Others Think

Set up your ~/.ssh/config and you don't need this - just ssh <host> <command> Even works with scp, too. Also, 'hostname' is already a command.
Fudo · 542 weeks and 5 days ago
How is this different from running stuff like ssh ls?
symgryph · 542 weeks and 2 days ago
This allow's you to use same command on local and remote host, without code modification or teaching end-users. It more simple than aliases (one symlink do all the work, no need to reload all shells when another command is added), it can be configured in one place and it just works.
mechmind · 542 weeks ago
I think he means to put in actual host names in place of "hostname". If so it just means you could type <hostname> <command> instead of ssh <hostname> <command> (assuming you have your .ssh/config set up) and I don't see that as a big enough advantage to outweigh possible conflicts between host names and other commands, and remembering to setup links for all the hosts you use on all your boxes. In terms of teaching end users, a custom system at your site is more of a training hassle than just using the standard commands unless there's a big savings, IMHO.
splante · 541 weeks and 6 days ago
I can only echo what splante said.
Norky · 541 weeks and 6 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: