Hi,
Thanks to all those who helped my try and solve my problem. I still cant seem to get it working because i cant install the Win32::API correctly (i think it's because of the firewall).
Any ways, i am trying to ping a network and print the output to a file and then insert the results into a database. I have modified the script to do it without the Win32::API module, but i have the following error. sorry i am new to perl and this forum.
i get the following error: use of uninitialised value in concatenation (.) or string line 73.
#!/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=$passwor
+d;") 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 cou
+nt, interval and packetsize of 100 for the IP Address. Read out to lo
+g file.
print "$cmd1\n";
system ($cmd1);
my $cmd2 = "ping -n 4 -l 200 $_> $file200"; # Ping count, inte
+rval 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 = <FILE100>;
close(FILE100);
open(FILE200, "$file200") || die "Could not open file $file200:$!\
+n";
my @file200 = <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;
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.