Are there any existing library for implementing a remote command line interface?
e.g.
Consider the case of gitolite
, when you do a git push origin
, it will ssh into the remote server and execute some code (namely hooks
, no server is needed for the whole transaction.
What I want to archive is something like that, e.g.
./remote get_up_time
It will invoke ssh into the remote machine and do execute the script get_up_time
already deployed
Assuming that ssh
is installed and that your public key is on the remote server (and thus, you do not need to provide a password), this would be a crude implementation:
#!/usr/bin/env ruby
host = ARGV.shift
command = ARGV.join(' ')
IO.popen("ssh #{host} \"#{command}\"") do |io|
io.sync = true
io.readlines.each { |line| puts line }
end
Usable like:
$ ./remote.rb www.example.com ls -l
You can expand this as needed to provide extra features, such as reading from stdin to provide ssh
a password or something.
Although it appears there is "no server", there is certainly an sshd
(a remote server) running on the remote system that allows this to work.
If you don't want to use ssh
, you will need to use another server running on the remote machine or write your own.