2

Using ruby ssh to exec a shell process that runs continuously on a remote machine. How can I enforce a duration for the ssh process to run and then have this process killed, and ruby ssh call end, moving on to subsequent code?

Purpose: invoke tests on a remote machine using ruby ssh for a specific duration.

example:

 Net::SSH.start( hostname.to_s, username.to_s, :password => pw.to_s ) do|ssh|
         output = ssh.exec("command line call that runs continuously")
         end

The only things I can think of doing: a) using Terminator to wrap around the ruby exec call for a duration of time b) use a perl helper function around the command line call as shown here

There must be something simpler than this right?

Community
  • 1
  • 1
mordechai
  • 127
  • 2
  • 10

1 Answers1

0

using a Watchdog / Terminator which sends a signal to the processes is the most common solution. Note that the remote process may have to be killed seperately!

Another way of doing this is to have both ends watch for a local "semaphore file" every X seconds... if the file is there with the correct PID in it, die gracefully!

So once your Watchdog timer expires, you can sync that file to the remote machine via scp or rsync, and copy one locally. and both jobs can look for them and terminate themselves..

of course you could also send a UNIX signal like SIGUSER

Tilo
  • 33,354
  • 5
  • 79
  • 106