From: Caveman Date: 2007-05-11T04:50:10+09:00 Subject: Re: Net::SSH exec command on remote host Saga, There are many ways to execute commands via the NET::SSH. Here is one option that will do what you want it to do: This encapsulates the commands: Net::SSH.start(h,u,p) do |session| shell = session.shell.sync cmd = shell.send_command "whatevercommand\n" p cmd.stdout cmd2 = shell.send_command "whatevercommand\n" p cmd2.stdout end end Or, if it's a standard command, you can do this: Net::SSH.start(h,u,p) do |session| shell = session.shell.sync cmd = shell.whatevercommand p cmd.stdout cmd2 = shell.whatevercommand p cmd2.stdout end end Cool thing about this is, if you are running a command that pipes to stderr, you can also capture that with cmd.stderr. Using the shell.send_command method allows you to send entire strings to be executed, such as: cmd = shell.send_command("cat /proc/partitions") p cmd.stdout Which allows you to capture the stdout as a string, then parse it as such: cmd = shell.send_command("cat /proc/partitions") devices = out.stdout devices.gsub!(/\n/,'') devices.gsub!(/([0123456789])/, '') disks<