1#!/usr/bin/perl 2#********************************************************************** 3# 4# adsl-state.pl 5# 6# Perl script which examines log files and summarizes state of ADSL link. 7# 8# Copyright (C) 2000 Roaring Penguin Software Inc. 9# 10# This program may be distributed according to the terms of the GNU 11# General Public License, version 2 or (at your option) any later version. 12# 13# $Id: adsl-state.pl,v 1.1.1.1 2008/10/15 03:31:00 james26_jang Exp $ 14# 15#********************************************************************** 16 17# This script analyzes your log files and summarizes the availability 18# of your ADSL link. 19# ASSUMPTIONS: 20# 1) You are using the adsl-connect script supplied with rp-pppoe to maintain 21# your connection. 22# 2) You are logging events of level "info" or above, and that "daemon" 23# facility messages are logged to /var/log/messages. 24# 25# To use: perl adsl-state.pl < /var/log/messages 26 27$state = "??"; 28$prevtime = "??"; 29 30sub up { 31 return if ($state eq "UP "); 32 33 my($line) = @_; 34 $line =~ /^(\S+)\s+(\S+)\s+(\S+).*/; 35 $month = $1; 36 $day = $2; 37 $time = $3; 38 $now = "$day $month $time"; 39 if ($state ne "??") { 40 print "DOWN from $prevtime to $now\n"; 41 } 42 $state = "UP "; 43 $prevtime = $now; 44} 45 46sub down { 47 return if ($state eq "DOWN"); 48 49 my($line) = @_; 50 $line =~ /^(\S+)\s+(\S+)\s+(\S+).*/; 51 $month = $1; 52 $day = $2; 53 $time = $3; 54 $now = "$day $month $time"; 55 if ($state ne "??") { 56 print "UP from $prevtime to $now\n"; 57 } 58 $state = "DOWN"; 59 $prevtime = $now; 60} 61 62while(<>) { 63 chomp; 64 if (/remote IP address/) { 65 up($_); 66 } elsif (/connection lost; attempting/) { 67 down($_); 68 } 69 $lastline = $_; 70} 71 72$lastline =~ /^(\S+)\s+(\S+)\s+(\S+).*/; 73$month = $1; 74$day = $2; 75$time = $3; 76$now = "$day $month $time"; 77print "$state from $prevtime to $now (end of log.)\n"; 78