How to start/run a ruby program in a remote machine in a LAN using a
ruby program in local machine?
···
--
Posted via http://www.ruby-forum.com/.
How to start/run a ruby program in a remote machine in a LAN using a
ruby program in local machine?
--
Posted via http://www.ruby-forum.com/.
Net-ssh. Or capistrano!
On Sep 21, 2012, at 12:29 AM, ajay paswan <lists@ruby-forum.com> wrote:
How to start/run a ruby program in a remote machine in a LAN using a
ruby program in local machine?--
Posted via http://www.ruby-forum.com/\.
Either using ssh, the netssh gem, or by using sockets to implement communication.
Brandon Weaver
On Sep 21, 2012, at 1:29 AM, ajay paswan <lists@ruby-forum.com> wrote:
How to start/run a ruby program in a remote machine in a LAN using a
ruby program in local machine?--
Posted via http://www.ruby-forum.com/\.
I am no expert but I use this to manage devices.
require 'rubygems'
require 'net/ssh'
require 'net/ssh/telnet'
class SSH
attr_accessor :errors
def initialize(creds)
begin
@ssh_session = Net::SSH.start(creds[:host], creds[:user], :password
=> creds[:password], :keys => )
@ssh = Net::SSH::Telnet.new("Session" => @ssh_session, "Prompt" =>
creds[:prompt])
@errors = false
rescue Exception => e
@errors = e
end
end
def cmd(command)
@ssh.cmd(command)
end
def close
@ssh_session.close
end
end
I would then create something like this depending on the device type I was
connecting to.
require './ssh.rb'
class Cisco_ssh < SSH
attr_accessor :config, :users
def initialize(creds)
begin
@host = creds[:host]
@users =
creds[:prompt] = /.*>|.*#/
super(creds)
@ssh.cmd("en\r#{creds[:enable]}")
@ssh.cmd("term len 0")
@config = @ssh.cmd("show run")
get_users
rescue Exception => e
@errors = e
end
end
def enable(pass)
@ssh.cmd("en\r#{pass}")
end
def termlen=(length)
@ssh.cmd("term len #{length}")
end
def close
termlen=24
@ssh_session.close
end
def update_config
@config = @ssh.cmd("show run")
get_users
end
private
def get_users
@config.lines.each do |line|
if line.include? "username"
user = {}
user[:username] = line.split[1]
user[:password] = line.match(/(password|secret).\d.*/)[0].split[2]
@users.push(user)
end
end
end
end
This stuff is pretty old so I should probably review it and clean it up.
Anyhow feel free to use it. I am still learning Ruby myself. Criticisms are
welcome!
On Fri, Sep 21, 2012 at 12:38 AM, Jam Bees <jam@jamandbees.net> wrote:
Net-ssh. Or capistrano!
On Sep 21, 2012, at 12:29 AM, ajay paswan <lists@ruby-forum.com> wrote:
> How to start/run a ruby program in a remote machine in a LAN using a
> ruby program in local machine?
>
> --
> Posted via http://www.ruby-forum.com/\.
>
--
vizualize.me/cliffrosson
Brandon Weaver wrote in post #1076989:
Either using ssh, the netssh gem, or by using sockets to implement
communication.Brandon Weaver
Thank you everybody.. for you amazingly helping words.. I think I'll go
for socket as I am not feeling comfortable with netssh!!! thanks again!
--
Posted via http://www.ruby-forum.com/\.
There's also DRb. Although then you have to
a) ensure a DRb server is running on the other machine
b) do authentication yourself.
It all depends... ![]()
Kind regards
robert
On Sat, Sep 22, 2012 at 2:53 PM, ajay paswan <lists@ruby-forum.com> wrote:
Brandon Weaver wrote in post #1076989:
Either using ssh, the netssh gem, or by using sockets to implement
communication.Brandon Weaver
Thank you everybody.. for you amazingly helping words.. I think I'll go
for socket as I am not feeling comfortable with netssh!!! thanks again!
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/