#!/usr/bin/perl -w use strict; use DBI; use Net::Ping; use CGI qw(:all) # This script (should) compare a copy of the master host file to the sizehist database # in order to determine what systems are currently not reporting their pstsize. my $dbh = DBI->connect( 'DBI:mysql:pstsize' ); my $sth = $dbh->prepare( 'select * from sizehist where ipaddr = ?' ); my $csv_inputfile = "/temp/use_me.txt"; my $NFcount = 0; my $NPcount = 0; my $ping = new Net::Ping; my $time_input_file = "/temp/lasttime.txt"; open my $fh, $time_input_file or die "can't open $time_input_file: $! \n"; while (my $line = <> ) { chomp ( $line ); my ( $time ) = $line; close $fh print header("text/plain"), start_html("Computers not reporting pstsize"); print <
Computers not reporting Outlook PST size
This will also show which of these are not responding to pings (useful for troubleshooting)

open my $fh, $csv_inputfile or die "can't open $csv_inputfile: $! \n"; while ( my $line = <$fh> ) { chomp( $line ); my ( $name, $ip ) = split /,/, $line; next if $ip =~ /[^\d\.]/; next if $name =~ /^dhcp-/; next if $ip =~ /^192\.168\.8\./; $sth->execute( $ip ); my $row = $sth->fetchrow_hashref; $sth->finish; unless ( $row ) { my $canPing = $ping->ping( $ip, 2 ); ++$NPcount unless $canPing; printf "%s (%s)%s\n", $name, $ip, $canPing ? '' : ' NO PING'; ++$NFcount; } } print "Hosts not found in DB: $NFcount\n"; print "Hosts not responding to PING: $NPcount\n"; print "The host file was last updated on $time\n";
close $fh; EndHTML print end_html;