So I am trying to ssh to a linux server from my app and run a script to provision a modem.
Here is the modem model.
class Modem < ActiveRecord::Base
require 'net/ssh'
belongs_to :customer
belongs_to :plan
has_one :neighborhood, through: :customer
# validates :mac, length: { maximum: 12 }
before_save :remove_dashes
enum status: [ :provisioned, :downgraded, :offline]
def remove_dashes
self.mac = mac.tr('-', '')
end
def add
ssh("dhcp-ctrl add -t modems -g 50Mbps -m 0123456789ab")
end
def change
ssh("dhcp-ctrl edit -t modems -g #{@group} -m #{self.mac}")
end
def remove
ssh("dhcp-ctrl delete -t modems -m #{self.mac}")
end
private
def ssh(script)
Net::SSH.start(self.neighborhood.ssh_host, self.neighborhood.ssh_user, { port: self.neighborhood.ssh_port, password: self.neighborhood.ssh_pass } ) do |ssh|
result = ssh.exec!(script)
puts result
end
end
end
I call c.modem.add c = Customer.first Here is the error I am getting from the console when I call it.
2.2.1 :032 > c.modem.add
=> "bash: -c: line 0: unexpected EOF while looking for matching `''\nbash: -c: line 1: syntax error: unexpected end of file\n"
What am I doing wrong?
Thanks!
--Tim
Net::SSHdoes not include a call tobash.