Skip to content

Instantly share code, notes, and snippets.

@psahni
Created May 28, 2013 14:05
Show Gist options
  • Save psahni/5662991 to your computer and use it in GitHub Desktop.
Save psahni/5662991 to your computer and use it in GitHub Desktop.
Run a command on the remote server
##############################################################
# Run a remote command on the remote server
# Dependency - net-ssh gem
##############################################################
require 'rubygems'
require 'net/ssh'
@hostname = "test.example.com"
@username = "username"
@password = "password"
@cmd = "ls -al"
begin
ssh = Net::SSH.start(@hostname, @username, :password => @password)
res = ssh.exec!(@cmd)
ssh.close
puts res
rescue
puts "Unable to connect to #{@hostname} using #{@username}/# {@password}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment