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 qwstandard);
# ------------------------------------------ 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?
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 qwstandard);
# ------------------------------------------ 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?