#!/usr/bin/perl -w ###################################################################################### use Net::Ping; #Escape quotes and equal signs @unxerp= ("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15"); #Quote for execution: chomp($date = qx#/bin/date #); chomp($month = qx#/bin/date +%B#); chomp($year = qx#/bin/date +%EY#); chomp($day = qx#/bin/date +%d#); chomp($hour = qx#/bin/date +%H#); chomp($min = qx#/bin/date +%M#); #chomp($webserver = qx#/sbin/hostname#); #or set whatever you like wants #$webserver = "name_of_webserver"; $webserver = "dbaweb"; $count=0; $file="/u02/app/apache2/htdocs/stats/history/$year/$month/$day/stats.$hour.$min.html"; $current_stats="stats.$hour.$min.html"; $workdir="/u02/app/apache2/htdocs/stats"; ###################################################################################### $i_am_running_file="/tmp/$0.txt"; die ("another copy of $0 is running ") if ( -e $i_am_running_file) ; system ("touch $i_am_running_file"); #mkdir first system ("mkdir -p $workdir/history/$year/$month/$day"); #open new file open (FH, ">$workdir/$current_stats") || die "cant open $current_stats:$!"; system ("ln -sf $workdir/$current_stats $workdir/stats.html"); ##################################################################################### sub printhtml { print FH ""; print FH " $server "; print FH "\<\/TD>"; } ################################################# print FH "$date

"; print FH "\"; ###########1-5 print FH ""; foreach $server (@unxerp[0..4]) { printhtml (); } print FH "\<\/TR>"; ##########6-10 print FH ""; foreach $server (@unxerp[5..9]) { printhtml (); } print FH "\<\/TR>"; #########11-15 print FH ""; foreach $server (@unxerp[10..14]) { printhtml (); } print FH "\<\/TR>"; ############16-20 print FH ""; foreach $server (@unxerp[15..18]) { printhtml (); } print FH "\<\/TR>"; ############21-25 #print FH ""; #foreach $server (@unxerp[20..20]) { #printhtml (); #} #print FH "\<\/TR>"; #End Table print FH "\<\/TABLE\>"; ########################################################################### print FH "History \ "; print FH "Problem Count"; print FH "

"; print FH "

"; ########################################################################### foreach $server (@unxerp) { $p = Net::Ping->new(); unless ($p->ping($server)) { print FH "

$server down\\\

"; $p->close(); next; } print FH "

$server\

"; print FH "

"; @cmdlist=("/usr/bin/df -k","/sbin/swapon -s", "/sbin/ps aux \| head -8", "/usr/bin/vmstat", "/usr/bin/uptime") ; foreach $cmd (@cmdlist) { print FH "

"; @result=`rsh $server $cmd`; foreach $line (@result) { if ( $line =~/9[0-9]\%\s*\// ) { $count++; print FH ""; } elsif ( $line =~/average/ ) { print FH ""; } else { print FH ""; } }#end forech line print FH "
$line
$server - $line
$line
"; print FH "

"; }#end foreach cmd } print FH "

$count problems\n

"; $i=$count; while ( $i > 0) { print FH "Problem $i

"; $i--; } chomp($date = qx#/bin/date #); print FH "$date

"; #move file in to new loc with new name system ("cp $workdir/stats.html $file") || warn "$file not copied: $!"; system ("rm $i_am_running_file");