I want to run a shell script from my Rails application. The script is started on the remote server via the net-ssh
Gem. Here is my code:
Net::SSH.start('localhost', 'user', :password => '1234', :port => port) do |session|
session.exec!("#{Rails.root}/script/myscript")
end
I have checked that the script is present in my local application. Script is taking about 1 hour for completion. I have two questions:
- Is this the right way for doing this?
- How can I run the script in the background?
The sample doc says that the simple, and quite proper way to run the
Net::SSH
session is the following:I recomment to pass at least password argument via shell environment to don't store it in the script plainly. Also you could use
micro-optparse
gem to pass other argument via command line. So it could be as follows:And run from command line:
Of course the support for
:port
argument can be added in the same manner.Use
nohup
orscreen
utitilies to run a script as a service in linux: