Perl Monks,
I seek your knowledge and wisdom again.
This time pertaining to enumerating WIN32::OLE response.
The issue is finding a timeout/hung session when retrieving
the win32 information (wmic) from a remote machine.
The code below is step by step, the failure does not occur until near the
bottom. I included this code for FYI.
eval
{
local $SIG{ALRM} = sub { warn "ALARM FOR GET WMIC L: \"" . __LINE_
+_ . "\" F: \"" . __FILE__ . "\"\n" }; # NB: \n required
alarm 10;
$wmicon = Win32::OLE->GetObject('winmgmts:' . '{impersonationLevel
+=impersonate, authenticationLevel=pkt}!\\\\' . $host . '\\root\\CIMV2
+\sms')
or $ok = 0;
alarm 0;
};
if($@){ $err = 1; $ret = "timeout while accessing wmi on machine $h
+ost"; return($err, $ret); }
else { } # didn't
The code above works as desired when a machine is offline,
the alarm feature is not the issue
$col = undef;
eval
{
local $SIG{ALRM} = sub { warn "ALARM FOR GET EXEC QUERY: \"$quer
+y\" L: \"" . __LINE__ . "\" F: \"" . __FILE__ . "\"\n" }; # NB: \n re
+quired
alarm 5;
$col = $wmicon->ExecQuery($query, "WQL", wbemFlagReturnImmediate
+ly | wbemFlagForwardOnly | WbemAuthenticationLevelPkt)
or $ok = 0;
alarm 0;
};
if($@){ $err = 1; $ret = "timeout while QUERY: \"$query\" wmi on
+machine $host"; return($err, $ret); }
else { } # didn't
if($ok == 0) { $err = 1; $ret = clean(Win32::OLE->LastError); retu
+rn($err, $ret); }
The code above works as expected
$objct = 0; $enabled = 0;
$obj = undef;
foreach $obj (in $col)
{
my $delete = 0;
if($debug == 1) { print "\tOBJ: \"$obj\" L: \"" . __LINE__ . "\"
+\n"; }
}
This code is where the problem occurs.
I dont understand what the "foreach $obj (in $col)"
actually does/executes on the back end.
Why not use "foreach $obj (keys % { $col })".
This does not work.
I need to trap/eval the "foreach $obj (in $col)",
to test for failure then exit/return. currently
when this hangs, the script stops until i kill it manually.
"$col" is a hash, however when I move this
scalar to a hash with
my %colhash = % { $col };
if($debug == 1) { print "DUMP COLHASH: \"" . Dumper(%colhash) . "\"
+L: \"" . __LINE__ . "\"\n"; }
The actual value is not the same as using the "foreach $obj (in $col)".
What is the difference in the "foreach" styles?
TIA,
Joe
P.S. I will sweeten the pot by honoring a single item
from a amazon wishlist (NOT GT $30USD).
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.