#! /usr/bin/perl -w # script to get pdu data from summary file created by # processPDULogs. Simply reads file pduname.out in $outputDir # with pduname being the value of the first parameter # returns the entry from the tab delimited file in the form # key value # where key is passed in as the second value # Copyright 2015, Rod, Daily Data, Inc. # Free to use, modify, change, anything you want # You do NOT have to give attribution, but it would be # appreciated. # Also, if you make changes and want to give them back, just send them to # us. Visit the http://www.dailydata.net and fill out the contact form my $pduName = shift; my $key = shift; my $outputExtension = 'out'; my $outputDir = '/home/apcpdu'; # retrieve one value (based on $key) from $datafile sub getValue { my $datafile = shift; my $key = shift; return -1 unless $key; # open data file and get line with key in it # maybe faster using grep??? open DATA, "<$datafile" or die "No data to read: $!\n"; my @lines = grep { /^$key\t/ } ; close DATA; # clean up line and return the value (second field of tab delim line) chomp( $lines[0] ); ($key,$value) = split ("\t", $lines[0] ); return $value; } die "Invalid PDU name" unless $pduName; my $filename = "$outputDir/$pduName.$outputExtension"; die "No Datafile" unless -e $filename; die "No key given" unless $key; print getValue( $filename, $key ); 1;