I would like to monitor a file located on remote host(win2k).so I want to use a perl script to get this file's info, and run it as a task.My computer runs win2k, either with the remote host. actually, I am very interesting with perl co-operate with WMI, this is sample script. but unfortunately. I really unfamiliar with WMI.
use strict; use Win32::OLE; my $output_delimeter = " "; my $argCount = scalar(@ARGV); my $Win32_Class = "Win32_Processor"; #Display help if if ($argCount == 0) { my @script_name = split m!\\!, $0; print <<"END"; Display information in the $Win32_Class class of a computer using Wind +ows Management Instrumentation (WMI). (The user account running this script must have access to the WMI repo +sitory of the target host.) $script_name[((scalar(@script_name)) - 1)] computer action rvalue Parameters: computer - the name of the computer to query action - index, query, get or browse Note: browse will return all of the properties in thi +s class. rvalue - the value or values you want back (LoadPercentage) kvalue - the number of processors you want to query (2) If a comma separated list of rvalues is passed to this script, the res +ults will be returned space delimited. Consult the Microsoft WMI documentation for more information about Win +dows Management Instrumentation. http://msdn.microsoft.com/library/en-us/wmisdk/wmi/wmi_start_page.asp Example: $script_name[((scalar(@script_name)) - 1)] localhost index $script_name[((scalar(@script_name)) - 1)] localhost browse $script_name[((scalar(@script_name)) - 1)] localhost get LoadPercen +tage 1 END exit; } #Parse through the command-line arguments and display the WMI informat +ion. WMIMain(@ARGV); sub WMIMain(\@) { my $computer = $_[0]; my $action = $_[1]; my $rvalue = $_[2]; my $kvalue = $_[3]; my $WMI_Key = "DeviceID"; my $class = "WinMgmts://$computer"; my $wmi = Win32::OLE->GetObject($class); my $i = 0; if ($wmi) { if ($action eq "index") { my $properties = "$WMI_Key"; my $computers = $wmi->ExecQuery("SELECT $properties FROM $ +Win32_Class"); if (scalar(Win32::OLE::in($computers)) lt "1") { print "\n Check the computer and class name.\n"; print " No information was found on the specified + class!\n"; return; } foreach my $pc (Win32::OLE::in($computers)) { $i++; properties($pc,$properties); if ($i < scalar(Win32::OLE::in($computers))) { print "\n"; } } } # if action = index if ($action eq "query") { my $properties = "$WMI_Key,$rvalue"; my $computers = $wmi->ExecQuery("SELECT $properties FROM $ +Win32_Class"); if (scalar(Win32::OLE::in($computers)) lt "1") { print "\n Check the computer and class name.\n"; print " No information was found on the specified + class!\n"; return; } foreach my $pc (Win32::OLE::in($computers)) { $i++; properties($pc,$properties); if ($i < scalar(Win32::OLE::in($computers))) { print "\n"; } } } # if action = query if ($action eq "get") { for(my $ID = 0; $ID < $kvalue; $ID++) { my $properties = $rvalue; my $computers = $wmi->ExecQuery("SELECT $properties FR +OM $Win32_Class Where $WMI_Key='CPU$ID'"); if($kvalue != 1) { print "CPU$ID:"; } if (scalar(Win32::OLE::in($computers)) lt "1") { print "-1$output_delimeter"; #print "\n Check the computer and class name.\n +"; #print " No information was found on the spec +ified class!\n"; #return; } foreach my $pc (Win32::OLE::in($computers)) { properties($pc,$properties); if($ID != ($kvalue - 1)) { print "$output_delimeter"; } } } } # if action = get if ($action eq "browse") { my $properties = "*"; my $computers = $wmi->ExecQuery("SELECT $properties FROM $ +Win32_Class"); if (scalar(Win32::OLE::in($computers)) lt "1") { print "\n Check the computer and class name.\n"; print " No information was found on the specified + class!\n"; return; } foreach my $pc (Win32::OLE::in($computers)) { $i++; properties($pc,$properties); if ($i < scalar(Win32::OLE::in($computers))) { print "\n"; } } } # if action = browse } # if wmi else { print "Unable to talk to WMI for $computer.\n"; } } #Loop through an object's properties. #Parameters: # 0 - a reference to the object # 1 - a single property to lookup sub properties($$) { my $node = $_[0]; my $properties = $_[1]; my $i = 0; if ($properties eq '*') { foreach ( Win32::OLE::in($node->{Properties_}) ) { viewPropertyBrowse($_); print "\n"; } } else { my @properties = split(',', $properties); foreach (@properties) { $i++; if (scalar(@properties) eq "1") { viewProperty($node->{Properties_}->{$_}); } elsif (scalar(@properties) gt "1") { viewPropertyMulti($node->{Properties_}->{$_}); if ((scalar(@properties) gt "1") & $i lt (scalar(@properti +es))) { print "$output_delimeter"; } } } } } #Display an object's property. #Parameters: # 0 - a reference to the property object sub viewProperty($$) { my $object = $_[0]; chomp ($object->{Value}); print "$object->{Value}"; } sub viewPropertyMulti($$) { my $object = $_[0]; chomp ($object->{Value}); print "$object->{Name}:$object->{Value}"; # print "$object->{Name}:".1024*$object->{Value}.""; } sub viewPropertyBrowse($$) { my $object = $_[0]; chomp ($object->{Value}); print "$object->{Name}:$object->{Value}"; # print "$object->{Name}:".1024*$object->{Value}.""; }
any suggestion or example code will be welcome.thanks in advance.

20050915 Janitored by Corion: Added readmore tags


In reply to How to monitor a file located on the remote host(win2k)? by ioiioi

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.