prabhakard has asked for the wisdom of the Perl Monks concerning the following question:
Here the code --------- use Time::Local; #use warnings qw(FATAL); #use diagnostics; #$SIG{__WARN__} = sub { $DB::single = 1; CORE::warn(@_) }; # variable settings $target="raksan"; $wwwpath="/$target"; $wwwrealpath="/home/nagios/stat/$target/htdocs"; $node = param("node"); $tmpgraph="rrd-$$.gif"; $now=time; $recenttimes = $now - 3600 * 36; $aix = 1 if ($node =~ /amsr/); # # Generate HTML page # system("/home/nagios/stat/scripts/ng_rrd2img.sh $target $node dig $rec +enttimes now 300 130 > $wwwrealpath/tmp/$tmpgraph"); print "Content-type: text/html\n\n"; print <<EOF <html><header><meta http-equiv="refresh" content="300"><title>NMON Per +formance Graphs</title></header><body bgcolor=#FFFFFF link=#006699 al +ink=#0000ff vlink=#006699> <body><BR><FONT FACE="arial"> <CENTER><h1>NMON Performance Graphs</h1></CENTER> EOF ; # # get the current day ,month, year for the form # ($sec,$min,$hour,$mday,$month,$year,$wday,$yday) = localtime($now); #($sec,$min,$mday,$month,$year,$wday,$yday) = localtime($now); $today = $mday; $tomonth = $month + 1; $toyear = $year + 1900; # # Create a row for each node, with the FORM, the sysinfo, and a graph +in it. # The nodes are all systems entered at the command line. # print <<EOF <table border="0" cellspacing="1"> <tr bgcolor="#A0A0FF"> <td colspan=5 rowspan=1 ><FONT SIZE=-5> <a name=$node></a></td> <form name="graph_$node" method=post action=/$target/cgi-bin/ng.pl tar +get=_blank> <input type=hidden name=node value=$node> <tr bgcolor="#C0C0C0"> <TD> <B>Select Graph(s)</B><BR> <select name=graph size=12 multiple> <option selected>CPU <option>Memory Use <option>Memory Totals <option>Memory Stats <option>Memory Ratios <option>Paging Act <option>Network Read <option>Network Write <option>Processes <option>Context Switches <option>Run Queue <option>Filesystem IO EOF ; if ($aix) { print <<EOF <option>File IO <option>IO Adapters Read <option>IO Adapters Write <option>System Calls EOF ; } print <<EOF </select> </TD> <TD> <table border="0" cellspacing="1"> <tr bgcolor="#C0C0C0"> <TD> <B>Select Range</B><BR> <select name=time size=9 > <option>Custom<br> <option selected>Today<br> <option>Yesterday<br> <option>This Week<br> <option>Last Week<br> <option>This Month<br> <option>Last Month<br> <option>This Year<br> <option>Last Year<br> </select> </TD> </tr> <tr bgcolor="#C0C0C0"> <td colspan=3 rowspan=1 align=center><BR><input type=submit value +="Create Graph!"></td> </tr> </table> </TD> <TD> <table border="0" cellspacing="1"> <tr bgcolor="#C0C0C0"> <td colspan=3 rowspan=1 align=center><B>Custom Range</B></td> </tr> <tr bgcolor="#A0A0FF"> <td colspan=3 rowspan=1 align=center>Start Date</td> </tr> <tr bgcolor="#C0C0C0"> <td colspan=1 rowspan=1 ><FONT SIZE=-1>Day</td> <td colspan=1 rowspan=1 ><FONT SIZE=-1>Month</td> <td colspan=1 rowspan=1 ><FONT SIZE=-1>Year</td> </tr> <tr bgcolor="#C0C0C0"> <TD> EOF ; print "<select name=startday>\n"; $i = 1; while ( $i <= 31 ) { $selected = ($i == $today) ? "selected" : ""; printf "<option $selected>%02d", $i; $i++; } print "</select></TD><TD>\n"; print "<select name=startmonth>\n"; $i = 1; while ( $i <= 12) { $selected = ($i == $tomonth) ? "selected" : ""; printf "<option $selected>%02d", $i; $i++; } print "</select></TD><TD>\n"; $i = 2015; print "<select name=startyear>\n"; while ( $i <= 2025 ) { $selected = ($i == $toyear) ? "selected" : ""; printf "<option $selected>%04d", $i; $i++; } print "</select></TD>\n"; print <<EOF </tr> <tr bgcolor="#A0A0FF"> <td colspan=3 rowspan=1 align=center>End Date</td> </tr> <tr bgcolor="#C0C0C0"> <td colspan=1 rowspan=1 ><FONT SIZE=-1>Day</td> <td colspan=1 rowspan=1 ><FONT SIZE=-1>Month</td> <td colspan=1 rowspan=1 ><FONT SIZE=-1>Year</td> </tr> <tr bgcolor="#C0C0C0"> <TD> EOF ; print "<select name=endday>\n"; $i = 1; while ( $i <= 31 ) { $selected = ($i == $today) ? "selected" : ""; printf "<option $selected>%02d", $i; $i++; } print "</select></TD><TD>\n"; print "<select name=endmonth>\n"; $i = 1; while ( $i <= 12 ) { $selected = ($i == $tomonth) ? "selected" : ""; printf "<option $selected>%02d", $i; $i++; } print "</select></TD><TD>\n"; $i = 2015; print "<select name=endyear>\n"; while ( $i <= 2025 ) { $selected = ($i == $toyear) ? "selected" : ""; printf "<option $selected>%04d", $i; $i++; } print "</select></TD>\n"; print <<EOF </tr> <tr bgcolor="#C0C0C0"> <td colspan=3 rowspan=1 > </td> </tr> <tr bgcolor="#A0A0FF"> <td colspan=3 rowspan=1 align=center>Specify Graph Size</td> </tr> <tr bgcolor="#C0C0C0"> <td colspan=3 rowspan=1 align=center><FONT SIZE=-1>Width:<input t +ype=text name=width value=400 size=3>Height:<input type=text name=hei +ght value=300 size=3></td> </tr> </table> </form> <TD ALIGN=CENTER> <H2>$node</H2> EOF ; $sysinfo = `sudo -u rsnagios ssh $node bin/sysinfo|sed s/-/_/`; ($model, $num_procs, $memory, $pssize, $kernelbits, $aixlevel, $uptime +) = split(/,/, $sysinfo); print <<EOF <table border="0" cellspacing="1"> <tr bgcolor="#A0A0FF"> <tr bgcolor="#C0C0C0"> <td colspan=1 rowspan=1 >Model</td> <td colspan=1 rowspan=1 >: $model</td> <tr bgcolor="#C0C0C0"> <td colspan=1 rowspan=1 >Procs</td> <td colspan=1 rowspan=1 >: $num_procs</td> <tr bgcolor="#C0C0C0"> <td colspan=1 rowspan=1 >Memory</td> <td colspan=1 rowspan=1 >: ${memory}MB</td> <tr bgcolor="#C0C0C0"> <td colspan=1 rowspan=1 >Paging</td> <td colspan=1 rowspan=1 >: ${pssize}MB</td> <tr bgcolor="#C0C0C0"> <td colspan=1 rowspan=1 >Kernel</td> <td colspan=1 rowspan=1 >: $kernelbits bit</td> <tr bgcolor="#C0C0C0"> <td colspan=1 rowspan=1 >OS</td> <td colspan=1 rowspan=1 >: $aixlevel</td> <tr bgcolor="#C0C0C0"> <td colspan=1 rowspan=1 >Uptime</td> <td colspan=1 rowspan=1 >: $uptime</td> </table> </TD> <td colspan=1 rowspan=1> <IMG src="${wwwpath}/tmp/$tmpgraph"> </tr> </table> <p><FONT SIZE=-1>The Performance data is recorded on the systems using + nmon and stored in Round Robin Databases by rrdtool. This interface +is created by nmon_grapher. </p> </body></html> EOF ; ------code ends here
Original content restored above and code tags added by GrandFather
What is the basic difference between run perl script from shell and via browser. how the result can be different on each method?--------- <c> use Time::Local; #use warnings qw(FATAL); #use diagnostics; #$SIG{__WARN__} = sub { $DB::single = 1; CORE::warn(@_) }; # variable settings $target="raksan"; $wwwpath="/$target"; $wwwrealpath="/home/nagios/stat/$target/htdocs"; $node = param("node"); $tmpgraph="rrd-$$.gif"; $now=time; $recenttimes = $now - 3600 * 36; $aix = 1 if ($node =~ /amsr/);
|
|---|