Friday, December 28, 2007

Small ruby script to remotely run a program

In case one needs to remotely run a program from some ruby application, an easy way to do that is using Net-ssh. It remotely runs commands through ssh.
After installing the gem through a simple
gem install net-ssh

the following script can be run in order to call the 'ls' application, used to list directory's contents:

require 'rubygems'
require 'net/ssh'

session = Net::SSH.start('your-host','your-user', 'your-password')

session.process.open("ls") do | ls |
ls.on_stdout do | p, data |
puts "#{data}"
end
end

No comments: