#!/usr/local/bin/perl use strict; use Win32::ODBC; # Enables ODBC database connectivity my $dsn = "postdev"; my $user = "archnas"; my $password = "something"; # Get all process related data from the database # Declare Variables my $rc; my $sql; my @ip; my $file100 = "c:/temp/ping100.log"; my $file200 = "c:/temp/ping200.log"; # Open ODBC session to database my($odbc_session) = new Win32::ODBC("dsn=$dsn; uid=$user; pwd=$password;") or die "Error connecting to $dsn\n"; # SQL $sql = " select DWH_LAN_IP FROM DAPO_CPCT_MGMT.DWH_Ntwk_Adr WHERE DWH_Ping_Flg = 'Y' "; # Submit SQL $rc = $odbc_session->Sql("$sql"); # Check for SQL errors if(defined $rc) { my $sql_error = $odbc_session->Error; my @sql_error = split /([-\[\]"])/,$sql_error; print "$sql\n"; print "SQL error: @sql_error[4,-2]\n"; exit; } # Retrieve answerset while($odbc_session->FetchRow()) { # Stores each IP Address in the @ip. my $ip_add = $odbc_session->Data(); #print "$ip_add\n"; push @ip, $ip_add; # Pushes each IP Address in the @ip to the top. } foreach (@ip) { my $cmd1 = "ping -n 4 -l 100 $_> $file100"; # Ping count, interval and packetsize of 100 for the IP Address. Read out to log file. print "$cmd1\n"; system ($cmd1); my $cmd2 = "ping -n 4 -l 200 $_> $file200"; # Ping count, interval and packetsize of 200 for the IP Address. Read out ot log file. system ($cmd2); open(FILE100, "$file100") || die "Could not open file $file100:$!\n"; my @file100 = ; close(FILE100); open(FILE200, "$file200") || die "Could not open file $file200:$!\n"; my @file200 = ; close(FILE200); print "$file100[9]\n $file100[11]\n"; print "$file200[9]\n $file200[11]\n"; #file100 is the variable holding the values to match on. $file100[9] =~ m/(^.*Sent\s=\s)(.*?)(\s,Received\s=\s)(.+?)(\s,Lost\s=\s)(.??)(\s.*$)/; my $sent = $2; my $received = $4; my $lost = $6; print "$sent, $received, $lost\n"; #$file100[9] =~ m/(^.*Sent\s=\s)(.*?)(,.*)/; #print ";$1;, ;$2;\n"; #$file100[11]=~ m/^.*Minimum\s=\s(.*)\s,Maximum\s=\s(.*)\s,Average\s=\s(.*)\s.*$/; #my $min = $1; #my $max = $2; #my $avg = $3; #print "$min, $max, $avg\n"; exit; }