Hi

I am loking for some help with a sed command or more particularly getting a sed 
command running in a perl script. 

Here is the statement which works if i run it from the console


Code:

winexe -U 'username'%'password' //host 'cmd /c dir /L /-C 
drive:\\dir\\FileName' | grep -i 'filename' | sed 's/^.\{17\}//g' | sed 's/^[ 
\t]*//'| sed 's/filename/ /g' | sed 's/^[ \t]*//;s/[ \t]*$//'




It outputs the file size only. Now I cant seem to get this to work in a pl 
script. I know perl has its own substituion commands but I have no idea how 
they work. 

This is the script im using so far, i know its not clean but ill do that once 
it works, it doesnt seem to work $output line


Code:

#!/usr/bin/perl
# 
# FILEURL = filepath and filename eg c:\windows\file.exe
# FILENAME = filename eg file.exe (this must be the same as the filename above 
in the FILEURL)
#

# Get Args
  $numargs = $#ARGV;
  
  $counternumber = @ARGV[0];
  $additionalargs = 4 + ((2 * $counternumber)-1);

  if  ( $numargs == $additionalargs ) {
        $hostname = @ARGV[1];
        $username = @ARGV[2];
        $password = @ARGV[3];
        $counter = @ARGV[4];
        $datapoint = @ARGV[5];

        splice(@ARGV, 0, 4);
        
        $count = @ARGV; 
        while ($count >= 1)  {
                $arg = @ARGV[0];
                push (@counters, $arg);
                shift (@ARGV);
                $arg = @ARGV[0];
                push (@datapoints, $arg);
                shift (@ARGV);
                $count = @ARGV;
        }
        }
  else  {
        print "filesize.pl NUMBER_OF_FILES HOSTNAME USERNAME PASSWORD FILEURL1 
FILENAME1 FILEURL2...\n";
        exit 0;
  }

# Format the counter string for Winexe
  $counter = '"';
  $counter = join('" "', @counters);
# Change the Username to work with winexe
  $username =~ s!//!\/!g;    

# Run Winexe and get the results

  $output =`\/usr/local/zenoss/common/bin/winexe -U '$username'%'$password' 
//$hostname 'cmd /c dir /L /-C "$counter"' | grep -i "$datapoint" | sed 
's/'"$datapoint"'/ /g' | sed 's/^.\{17\}//g' | sed 's/'"$datapoint"'/ /g' | sed 
's/^[ \t]*//;s/[ \t]*$//'`; 


# Check the output, and do basic error checking
  if ($output)  {
        $w = index ($output, "ERROR");
        $x = index ($output, "Warning");
        $y = index ($output, "Error");
        $z = index ($output, "WARNING");
        $checkerror = $w + $x + $y + $z;
        if ($checkerror != -4)  {
                print "Errors Found:$output\n";
                exit 0;
        }
  } 
  else  {
                print "Errors Found:$output\n";
                exit 0;
  }

# Get the performance counter fields
  @result_lines = split (/\n/, $output);
  @results_fields = split (/,/,@result_lines[2]);

# Put perfcounter results into an array
  shift (@results_fields);  
  $count = @results_fields; 
  while ($count >= 1)  {
        $results = @results_fields[0];
        $results =~ s!"!!g;
        $results = sprintf("%.2f", $results);
        push (@perfcounters, $results);
        shift (@results_fields);
        $count = @results_fields;
  }

# Create the final output from the perfcounter and datapoint arrays  

  $count = @datapoints;
  $perf_output = "";
  while ($count >= 1)  {
        $results = @datapoints[0];
        $results = $results . '=';
        shift (@datapoints);
        
        $results = $results . @perfcounters[0];
        $results = $results . ' ';
        shift (@perfcounters);
        $perf_output = $perf_output . $results; 
        $count = @datapoints;
  }
# Output the final performance counters back
  print "OK|$perf_output\n";




any ideas

Thanks for any help in advance[/code]




-------------------- m2f --------------------

Read this topic online here:
http://forums.zenoss.com/viewtopic.php?p=26123#26123

-------------------- m2f --------------------



_______________________________________________
zenoss-users mailing list
[email protected]
http://lists.zenoss.org/mailman/listinfo/zenoss-users

Reply via email to