Created
May 28, 2013 14:05
-
-
Save psahni/5662991 to your computer and use it in GitHub Desktop.
Run a command on the remote server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################## | |
# 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