Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New to perl, trying to debug sarplot script

Status
Not open for further replies.

Depdiver

MIS
Sep 11, 2003
11
US
As part of my introduction to perl I have copied a script form a website to create graphs from sar data. Upon running the script I have received the following error, and quite frankly, have no idea what it means.

Can't find string terminator "END" anywhere before EOF at ./sarplot.cgi line 16.

The script is as follows:

#!/usr/bin/perl -w
# sarplot.cgi, shs 10/29/02, plot sar data

# --------------------------------------------- modules use IPC::Open3; use CGI qw:)standard);
# ------------------------------------------ parameters read(STDIN,$temp,$ENV{'CONTENT_LENGTH'}); @pairs=split(/&/,$temp); foreach $item(@pairs) { ($key,$content)=split(/=/,$item,2); $content=~tr/+/ /; $content=~s/%(..)/pack("c",hex($1))/ge; $content=~s/\012//g; $content=~s/\015//g; $content=~s/ //g; $fields{$key}=$content; }

$dt=`date`; # save date for title
chomp($dt); $opt=$fields{'opt'}; # get sar option if passed @sarstats=`sar -$opt`; # capture data from sar $data="/tmp/stats$$"; # identify temp file
# --------------------------------------- process sar output open DATA, ">$data" or die "Cannot open $data for writing";

foreach $line (@sarstats) {
if ( $line=~/\d+:\d+:\d+.+[a-z]/ ) { # capture column headings @hdgs=split ' ',$line; # store in array for later use } else{ print DATA "$line"; } } close DATA; $sz=$#hdgs; # number of data columns
# ------------------------------------------- run gnuplot $| = 1; # disable buffering my $gnuplot = "/opt/gnu/bin/gnuplot";my $pid = open3(\*GNUPLOT, \*GRDATA, \*ERROR, $gnuplot);

# send commands to gnuplot
print GNUPLOT << "END"; set term png color set title "$dt (sar -$opt)"; set timefmt "%H:%M:%S" set xdata time set format x "%H:%M:%S" set xtics border rotate set xrange ["00:00" to "23:59"] END

# send command line for each data column
print GNUPLOT "plot "; for ($x=2; $x<=$sz; $x++) { $h=$x-1; print GNUPLOT "'$data' using 1:$x t '$hdgs[$h]' with line,"; } print GNUPLOT "'$data' using 1:$x t '$hdgs[$x-1]' with line";
close(GNUPLOT);

# identify data type
print header("image/png");

# send the image back to the browser
while ($length = sysread(GRDATA,$content,1024)) { syswrite(STDOUT,$content,$length); }

close(GRDATA);
system("rm $data");

Can someone explain to me why this is failing?
 
The issue is that when you print a block of text, the terminator needs to be on it's own line with no spaces or characters in front of it. In the code above, you have it at the end of your line. There should also be a blank line after the terminator.

Your code:
Code:
# send commands to gnuplot
print GNUPLOT << "END"; set term png color set title "$dt (sar -$opt)"; set timefmt "%H:%M:%S" set xdata time set format x "%H:%M:%S" set xtics border rotate set xrange ["00:00" to "23:59"] END

Corrected code:
Code:
# send commands to gnuplot
print GNUPLOT << "END";
set term png color set title "$dt (sar -$opt)"; set timefmt "%H:%M:%S" set xdata time set format x "%H:%M:%S" set xtics border rotate set xrange ["00:00" to "23:59"]
END

# send command line for each data column

- Rieekan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top