Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Hello PerlMonks, i am new to the perl programming. but managed to get some script put together to get the Time zone information for all the servers using WMI Query. i want to implement threads to make this run faster. i have zero knowledge on threads. but using one example i find i tried to implement wmi query. when i run the script with WMI, i was able to get the list of server names with thread. when i add WMI query, the script is crashing perl with the following messsage.

perl TimeZoneCheck.pl Starting main program 0 server1 1 server2 Host server1 is alive Host server2 is alive BPYTSM.JDNET.DEERE.COM India Standard Time (GMT+05:30) Chennai, Kolkata, Mumbai, New Delhi (GMT+05:30) Chennai, Kolkata, Mumbai, New Delhi Free to wrong pool 49c7480 not 163ea8, <FILE> line 5 during global destruction.

i have active perl version 5.10.0

This is perl, v5.10.0 built for MSWin32-x86-multi-thread (with 9 registered patches, see perl -V for more detail) Binary build 1005 290470 provided by ActiveState http://www.ActiveState.com Built May 24 2009 12:17:36

i also request if you have any suggestions on better error handling for wmi queries

Following is the script i am using.
use warnings; use threads; use threads::shared; use Net::Ping; use Switch; use Net::DNS; use Win32::OLE qw(in with); use Carp; use constant wbemFlagReturnImmediately => 0x10; use constant wbemFlagForwardOnly => 0x20; $Win32::OLE::Warn = 3; print "Starting main program\n"; open FILE, "c:\\serverping.txt" or die "could not open the file"; my @lines = <FILE>; $linecount = scalar @lines; $row = 0; $line =$lines[$row]; $line =~ s/^\s+//m; $line =~ s/\s+$//m; $mainparam = $row.':'.$lines[$row]; $thr0 = threads->new(\&GetTimeZone, $mainparam); $row++; $mainparam = $row.':'.$lines[$row]; $thr1 = threads->new(\&GetTimeZone, $mainparam); $row++; while(1){ if ($thr0->is_joinable()) { $thr0->join; if ($row<$linecount){ $mainparam = $row.':'.$lines[$row]; $thr0 = threads->new(\&GetTimeZone, $mainparam); $row++; } } if ($thr1->is_joinable()) { $thr1->join; if ($row<$linecount){ $mainparam = $row.':'.$lines[$row]; $thr1 = threads->new(\&GetTimeZone, $mainparam); $row++; } } $thread_count = threads->list(); #print "$thread_count \n"; last if ($row==$linecount && $thread_count == 0); } print "End of main program\n"; close FILE; sub GetTimeZone { my $paramsub = shift; my @subparam = split(/:/, $paramsub); my $subrow = $subparam[0]; my $subhost = $subparam[1]; $subhost =~ s/^\s+//m; $subhost =~ s/\s+$//m; # Create a new ping object $pingit = Net::Ping->new("icmp"); my $timeout = 10; print "\n$subrow \t $subhost \n"; my $user="domain\\username"; my $pwd="password"; my $locatorObj =Win32::OLE->new("WbemScripting.SWbemLocator") or d +ie "ERROR CREATING OBJ"; $locatorObj->{Security_}->{impersonationlevel} = 3; if( $pingit->ping($subhost, $timeout) ) { print "Host ".$subhost." is alive\n"; eval { my $objWMIService = $locatorObj->ConnectServer($subhost, + "root\\cimv2", $user, $pwd); if (Win32::OLE->LastError()) { print "$_\n"; Win32::OLE->LastError(0); # this clears your error } else { $colItems = $objWMIService->ExecQuery ("Select * from Win32_Timezone","WQL",wbemFlagRetu +rnImmediately | wbemFlagForwardOnly); if (Win32::GetLastError()) { print "$subhost : $_\n"; Win32::OLE->LastError(0); # this clears your error } else{ foreach my $objItem (in $colItems) { print "\n$subhost \t $objItem->{StandardNa +me} \t $objItem->{Caption} \t $objItem->{Description} \n"; } } } }; if ($@) { print "Warning: Error querying object $subhost: $@\n"; } } else { print "Warning: ".$subhost." appears to be down or icmp packets +are blocked by their server\n"; } $pingit->close(); }

In reply to WMI query with Threads by vamsinm

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!
  • 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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (12)
    As of 2015-07-02 21:53 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (45 votes), past polls