Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Script Won't Exit After Call to System

Reply
Thread Tools

Script Won't Exit After Call to System

 
 
David Sokoloff
Guest
Posts: n/a
 
      03-08-2009
I have a small script (see http://pastie.org/411010) that will check to
see if my ssh tunnel has died, and if so, will create a new one. It
works, except that if it does need to re-open a tunnel (through Kernel's
'system' call), the script never exits. Maybe it isn't a big deal (say
so if you think so), but I'm not sure why the script doesn't exit. It
*does* re-open the tunnel successfully. Furthermore, if you execute from
the command line the same ssh command I'm executing through Ruby's
'system' call, the tunnel does successfully go to the background.

Thanks for any insight.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Brian Candler
Guest
Posts: n/a
 
      03-08-2009
David Sokoloff wrote:
> I have a small script (see http://pastie.org/411010) that will check to
> see if my ssh tunnel has died, and if so, will create a new one. It
> works, except that if it does need to re-open a tunnel (through Kernel's
> 'system' call), the script never exits. Maybe it isn't a big deal (say
> so if you think so), but I'm not sure why the script doesn't exit. It
> *does* re-open the tunnel successfully. Furthermore, if you execute from
> the command line the same ssh command I'm executing through Ruby's
> 'system' call, the tunnel does successfully go to the background.
>
> Thanks for any insight.


Rather than mess around with how the ssh command-line client may or may
not background itself, I suggest two alternatives:

1. Use Net::SSH as the client and get it to do the forwarding for you.
This is a pure Ruby solution and hence no issues with forked processes.
From the docs:

ssh.forward.local(17055, "mail.example.com", 143)

2. If you're going to use the openssh client, run it in the foreground
and hold onto it from the Ruby client. Then you'll know immediately when
it has terminated, zombie-free, and can restart it when necessary;
scanning the output of 'ps' is no longer necessary.

You might do this using IO.popen or the pty library, but even if just
using system() this can be done in a Ruby thread.

Aside: I don't know if you realise, but you can open multiple forwarding
ports in the same ssh command line:

ssh -Lxxxx -Lyy:yy:yy -Lzz:zz:zz host.example.com

HTH,

Brian.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
In a Perl script 'exit 1' returns exit status 0! kaleem Perl Misc 8 12-14-2006 12:52 AM
Exit code of a batch (using exit /B) Joe Smith Java 4 11-08-2006 12:25 PM
Code to Exit Web App and Exit Internet Explorer =?Utf-8?B?U2FuZHk=?= ASP .Net 7 08-05-2005 01:55 AM
Script continues running after an exit() call? Debo Perl Misc 3 06-18-2005 08:58 AM
exit after process exit ajikoe@gmail.com Python 2 05-31-2005 08:11 PM



Advertisments