Closed leandrosardi closed 2 years ago
Here is the ruby code that I need to get working:
logger.logs "kill... "
output = host.ssh.exec!("pkill xterm; pkill chrome; pkill ruby;").strip
logger.logf "done (#{output.strip})"
logger.logs "get display code... "
display = host.ssh.exec!("ps -ef |grep Xauthor | grep -v grep | nawk '{print $9}'").strip
logger.logf "done (#{display.strip})"
s = "DISPLAY=#{display};export DISPLAY;/bin/bash --login -c \"/home/bots/run.worker.prod.sh\" &"
logger.logs "run (#{s})... "
stdout = host.ssh.exec!(s)
logger.logf "done (#{stdout.strip})"
Here is the fix:
s = "bash --login -c 'sleep 600' >/dev/null 2>&1 &"
print "run (#{s})... "
stdout = ssh.exec!(s)
puts "done (#{stdout.strip})"
I am having a hard time running bash commands in background from a Ruby script.
For this question, I am using a simplified example.
This is how commands are working as expected when I run them from PuTTY.
Now, I try to replicate this from Ruby, using this little script shown below:
This is the outout I get when I run such a Ruby script:
For your analysis, here is the transcription of the Ruby script: