I was developing a script to work on a list of machines - basically finding out whether the Anti virus in the machine is working or not and if not try to do some remediation. I observed the script getting stuck on certain machines when it fails to stop the Anti virus client due to some particular reason which I'm not sure. My question is - Is there a way in Perl to skip the problem machine ? say after the script try for sometime and go to the next machine if it fails on the first machine.
foreach $machine (@old)
{
chomp ($machine);
stopsmc(); #Function to Stop the AV client
timedelay(); #Function to delay time
startsmc(); #Function to Start the AV client
}
sub stopsmc{
my $stop='psexec' . " " . '\\\\' . $machine . " " .$smc. " " .' -
+p ' . " " . "[password]". " " . "-stop";
if(system("$stop"))
{
print "SMC Stopped,";
}
else
{
print "SMC Not Stopped,";
}
}
I'm using a sysinternal psexec utility to stop the AV client service. Here the stopsmc() function may continuously try to stop the service but does not succeed and hence the script is unable to go forward with the next machine. I would like to know whether any logic can help me - to go to the next machine if one machine get stuck for a particular time period. I was thinking something like this if stopsmc did not give a result for say 5 minutes or so go to next machine. Let me know If I did not make myself clear.
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.