#! /usr/local/bin/perl $uncorrected = 0; $corrected = 0; $retrain = 0; $signal = 0; $opt_d = 0; #Local storage directory $workdir = "/usr/local/etc"; # Bytes on wan0-0 $byfile = ".ciscoby"; $bypath = join("/", $workdir, $byfile); # S/N file. $snfile = ".ciscosn"; $snpath = join("/", $workdir, $snfile); # error summation file $errfile = ".ciscoerrs"; $errpath = join("/", $workdir, $errfile); # RS errors file. $rsfile = ".ciscors"; $rspath = join("/", $workdir, $rsfile); # execute "cisco" on firewall for statistics $cisco = "/usr/local/etc/cisco"; open(QP, "rsh -n $cisco |") || die "cannot open pipe to DSL router ($!)\n"; # Interpret information from expect script if ($opt_d) { open(LF, ">> /var/log/cisco.expect.log"); print LF "====\n", `date`; } while () { print LF if ($opt_d); chop; s/\r/\n/; if (/uptime/) { $uptime = $_; print LF "Uptime: ", $uptime if ($opt_d); } if (/(\d+)\s+Kbps\s+down;\s+(\d+)\s+Kbps\s+up;/) { $speed[0] = $1; $speed[1] = $2; } elsif (/Line\s+Quality\s+(\d+)\s+dB/) { print LF "Line quality S/N: $1\n" if ($opt_d); $signal = $1; } $rscount = join("/", $workdir, ".rscount"); if (/uncorrected\s+RS\s+errors:\s+(\d+)\s+\#\s+of\s+corrected\s+RS\s+errors:\s+(\d+)/) { print LF "uncorrected RS errors: $1\n" if ($opt_d); print LF " corrected RS errors: $2\n" if ($opt_d); $werrs[0] = $1; $werrs[1] = $2; if ( open(EF, "< $rscount")) { $errcount = ; ($uncorrected, $corrected) = split(' ', $errcount); close(EF); } $retrain = 10 if (($werrs[0] - $uncorrected) < 0 || ($werrs[1] - $corrected) < 0); if ( open(EF, "> $rscount")) { print EF $werrs[0], " ", $werrs[1], "\n"; close(EF); } } elsif (/bytes\s+Rx:\s+(\d+)\s+Tx:\s+(\d+)/) { print LF "wan0-0 bytes in: $1\n" if ($opt_d); print LF "wan0-0 bytes out: $2\n" if ($opt_d); $wan[0] = $1; $wan[1] = $2; } elsif (/CRC\s+errors:\s+(\d+)/) { print LF "CRC errors: $1\n" if ($opt_d); $werrs[2] = $1; } elsif (/rejected\s+Tx\s+packets:\s+(\d+)/) { print LF "Tx errors: $1\n" if ($opt_d); $werrs[3] = $1; } } close(LF) if ($opt_d); close(QP); if (! defined($signal)) { print LF "unable to get S/N\n"; } if (open(BY, "> $bypath")) { print BY $wan[0], "\n"; print BY $wan[1], "\n"; print BY $uptime; print BY "Cisco675 Bytes\n"; close(BY); } if (open(SF, "> $snpath")) { print SF $retrain, "\n"; print SF $signal, "\n"; print SF $uptime; print SF "Cisco675 S/N\n"; close(SF); } if (open(EF, "> $errpath")) { print EF $werrs[0], "\n"; print EF $werrs[2], "\n"; print EF $uptime; print EF "Cisco675 RS and CRC errors\n"; close(EF); } if (open(RF, "> $rspath")) { print RF ($werrs[0] * 10), "\n"; print RF $werrs[1], "\n"; print RF $uptime; print RF "Cisco675 RS errors\n"; close(RF); } exit(0);
Scott Presnell
Last modified: Friday, October 12, 2001 08:39 PDT