Yes there is, it's named alarm. I'm not exactly sure what you mean by a remote shell... are you using Expect, or Net::Telnet or system('sh') or something else entirely? Nevertheless, your code is going to look something like this:

eval { local $SIG{ALRM} = sub { die "too long\n" }; alarm 30; #seconds system( '/usr/local/bin/scp', 'me@example.com:foo.txt', '.' ); alarm 0; }; if ($@ eq "too long\n") { # time out } elsif ($@) { #something else went wrong } else { # ok }

Note that your remote command could involve a Win32 machine, however you cannot run this code on a Win32 machine as alarm is not implemented on that platform. Also not that you want your signal handler $SIG{ALRM} to be as simple as possible. The more it does, the more chance you run the risk of dumping core and other other unpleasant things


print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u'

In reply to Re: Time out (use alarm) by grinder
in thread Time out by Ras

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.