#!/usr/bin/perl -w $load = `/usr/bin/pdsh -w n0001,n0002,n0003,n0004,n0005,n0006,n0007,n0008 w 2>&1 | grep 'load' | awk '{print \$NF}' | awk '{sum+=\$1} END { print sum/8.0}'`; open IN, "/srv/www/html/data/pages/status.txt" or die "Can not open status.txt\n"; open OUT, ">/tmp/load_status" or die "Can not open temporary file\n"; $first = 0; while ( $line = <IN> ) { chomp( $line ); if ( $line =~ /^(\d?\d+.\d+, )/ && $first == 0 ) { printf OUT "$', %4.2f\n", $load; $first = 1; } else { print OUT "$line\n"; } } close OUT; close IN; system("/bin/mv -f /tmp/load_status /srv/www/html/data/pages/status.txt"); system("/usr/bin/wget -q -O - \"http://norma.mbg.duth.gr/index.php?id=status\" 2>&1 > /dev/null"); exit;
#!/usr/bin/perl -w open IN, "/srv/www/html/data/pages/status.txt" or die "Can not open status.txt\n"; open OUT, ">/tmp/load_status" or die "Can not open temporary file\n"; $first = 0; while ( $line = <IN> ) { chomp( $line ); if ( $line =~ /^(\d?\d+.\d+, )/ ) { if ( $first == 0 ) { @words = split(', ', $line); $new_aver = 0.0; for ( $i=288 ; $i < 336 ; $i++ ) { $new_aver += $words[$i]; } $new_aver /= 48.0; $first = 1; print OUT "$line\n"; } else { printf OUT "$', %4.2f\n", $new_aver; } } else { print OUT "$line\n"; } } close OUT; close IN; system("/bin/mv -f /tmp/load_status /srv/www/html/data/pages/status.txt"); system("/usr/bin/wget -q -O - \"http://norma.mbg.duth.gr/index.php?id=status\" 2>&1 > /dev/null"); exit;
Discussion