Greetings Monks,

I have a program that goes through about 400 WINNT computers looking for the service pack number. I use a third party program, pstools, to find this info connecting though the Shell module.

My problem is with unsuccessful results. The psinfo program return sucessful results in about 4 seconds but if it can't find, or can't connect to a computer it can take more than a minute. This problem makes my program run longer than I would like

Is there any way, with the shell module (or backticks, qx(), etc), to kill a shell escape if it take more than, say 10 seconds?

use Shell; use strict; use Spreadsheet::WriteExcel; my @computers = qw(big list of computers); my $workbook = Spreadsheet::WriteExcel->new("ServicePack.xls"); my $worksheet = $workbook->addworksheet(); my $rowcount = 0; for my $computer(@computers){ $user{'computer'} = $computer; $user{'servicepack'} = get_sp($computer); $worksheet->write($rowcount, 0, $user{'computer'}); $worksheet->write($rowcount, 1, $user{'servicepack'}); $rowcount++; } #Function: get_sp #Arguments: Computer Name #Return Value: Service Pack number sub get_sp{ my $cpu = shift @_; my $info= psinfo('\\\\'. $cpu); my @lines = split("\n",$info); @lines = grep {/(Service Pack:)/i} @lines; s/[\w\s]+:\s+(\d)$/$1/ for @lines; my $servicepack = $lines[0]; return ($servicepack || "unknown"); }

In reply to Dealing with timeouts using the Shell module by thunders

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.