Rails and Net:SSH
<p>So I am trying to ssh to a linux server from my app and run a script to provision a modem. </p>

<p>Here is the modem model.</p>

<pre><code>  class Modem &lt; 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
</code></pre>

<p>I call c.modem.add 
c = Customer.first
Here is the error I am getting from the console when  I call it.</p>

<pre><code>2.2.1 :032 &gt; c.modem.add
 =&gt; "bash: -c: line 0: unexpected EOF while looking for matching `''\nbash: -c: line 1: syntax error: unexpected end of file\n" 
</code></pre>

<p>What am I doing wrong?</p>

<p>Thanks!</p>

<p>--Tim</p>