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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |