The script is run under windows 2003. This is an example of the script:
#!/usr/bin/perl use strict; use Warnings; use HTTP::Status; use HTTP::Response; use HTTP::Request; use LWP::UserAgent; if (@ARGV < 2) { print "USAGE: IsPageAvailable [-r] <MonitorName> <URL> <Hosts file +> [Http::Host]\n"; } else { # Treat the -r option, in wich case the screap will search in the +response returned to SUCCEED # string and treat the returned monitor accoringly. my $checkResponse = 0; if ($ARGV[0] eq "-r") { $checkResponse = 1; shift @ARGV; } my ($strMonitorName, $strURL, $hosts, $httpHost) = @ARGV; # Use the configuration file only if specefied. if (defined($hosts)) { # Generate the computerName and domainName variables used late +r to search in the hosts file my $computerName = lc($ENV{'COMPUTERNAME'}); $strURL =~ /^http.*\/\/(.+?)[\:\/]/; my $domainName = $1; my $ip; # Convert the domain using the hosts file supplied open (HOSTS, '<', $hosts) or die "Cant open configuration file + $hosts\n"; END: while (my $line = <HOSTS>) { if ($line =~ /$computerName:$domainName:(.+)/) { $ip = $1; chomp($ip); last END; } } close(HOSTS); # No entries in the hosts found die "No entries in $hosts file found for this machine ($comput +erName, $domainName)\n" if (!defined($ip)); # Substitute in the URL to the found $ip $strURL =~ s/$domainName/$ip/; } # Perform the GET command print "Performing GET on $strURL\n"; my $ua = LWP::UserAgent->new; $ua->timeout(15); # We can define the httpHost my $request; if (defined($httpHost)) { $request = HTTP::Request->new(GET => $strURL, HTTP::Headers->n +ew(Host => $httpHost)); } else { $request = HTTP::Request->new(GET => $strURL); } my $response = $ua->request($request); my $nCode = $response->code; my $nMonitorValue; my $nReturnCode = $response->code; print "Return Code = $nReturnCode\n"; # Check the returned code and format the opcmon command if ($nReturnCode == 200) { if ($checkResponse) { if ($response->content =~ /SUCCEEDED/m) { $nMonitorValue = 0; } else { $nMonitorValue = 1; } } else { $nMonitorValue = 0; } } else { $nMonitorValue = 1; } # Send the opcmon print "opcmon value = $nMonitorValue\n"; my $strCmd ="opcmon $strMonitorName=$nMonitorValue"; my $exit = system($strCmd); exit $exit; }

In reply to Re^2: perl cpu usage on windows machines by leonidlm
in thread perl cpu usage on windows machines by leonidlm

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.