I've been having trouble with my ISP (Comcast) recently going up and down many times a day for many minutes a day.
I wrote a little script to go out to google every 5 minutes and it logs every time the connection is down. It will then log the next time the connection is back up.
Code:
1 #!/bin/bash
2 # echo any arguments
3
4 DAT_FILE="/var/log/scripts/inetstate.dat"
5 LOG_FILE="/home/cmfarley/connected.log"
6 echo $1
7
8 # Get the date and time in spreadsheet friendly format
9 DATE=$(date +%D' '%T)
10
11 # Try to connect. If successful $CON="Google", else empty
12 CON=$(lynx -dump -connect_timeout=10 google.com|grep -i Lucky|cut -d ' ' -f5)
13
14 # Get the last entry in the log
15 TEMP=$( tail -1 $LOG_FILE |cut --complement -d ',' -f1|cut -d ' ' -f2)
16
17 # if an argurment (DEBUG) echo $TEMP
18 if [ $1 ]
19 then
20 echo $TEMP
21 echo $LOG_FILE
22 VAR=`echo $1`
23 echo $VAR
24 else
25 VAR="XXX"
26 fi
27
28 if [ $VAR == "-date" ]
29 then
30 date +%D >> $LOG_FILE
31 else
32
33 #if $CONNECT is empty...
34 if [ -z $CON ]
35 then
36 echo "Not Connected" > $DAT_FILE
37 # if $TEMP !empty, last attemp was connected, so log the disconnect
38 # else the last attempt was disconnected so do nothing
39 if [ $TEMP ]
40 then
41 echo "$DATE, " >> $LOG_FILE
42 fi
43
44 else
45 echo "Connected to $CON" > $DAT_FILE
46 # if $TEMP is empty, last attemp was !connected, so log the connection
47 # else the last attempt was connected so do nothing
48 if [ -z $TEMP ]
49 then
50 echo "$DATE" >> $LOG_FILE
51 fi
52
53 fi
54 fi # -date
The output of the log file looks like this:
Code:
DOWN, UP
07/29/08
07/29/08 19:25:01,
07/29/08 19:30:01
07/29/08 21:50:01,
07/29/08 21:55:01
07/30/08
07/30/08 14:05:01,
07/30/08 14:10:01
07/30/08 18:40:01,
07/30/08 18:50:01
07/31/08
07/31/08 21:50:01,
07/31/08 21:55:01
08/01/08
08/01/08 05:20:01,
08/01/08 05:25:01
08/01/08 10:00:01,
08/01/08 10:10:01
08/01/08 10:15:01,
08/01/08 10:20:01
08/01/08 11:30:01,
08/01/08 11:35:01
08/01/08 11:40:01,
08/01/08 11:45:01
08/02/08
08/02/08 01:50:01,
08/02/08 01:55:01
08/02/08 02:00:01,
08/02/08 02:05:02
08/02/08 17:45:01,
08/02/08 17:50:01
08/02/08 17:55:01,
08/02/08 18:00:01
08/02/08 19:20:01,
08/02/08 19:25:01
08/03/08
08/04/08
08/04/08 00:20:01,
08/04/08 00:25:01
08/04/08 00:30:01,
08/04/08 00:50:01
08/04/08 04:25:01,
08/04/08 04:30:01
08/04/08 20:20:01,
08/04/08 20:25:01
08/05/08
08/05/08 10:30:01,
08/05/08 10:35:01
Line 41 outputs the down time stamp and line 50 outputs the up time stamp. What I want is the up time stamp to be on the same line as the down time stamp so they are in pairs.
Kind of like this:
Code:
...
08/04/08
08/04/08 00:20:01, 08/04/08 00:25:01
08/04/08 00:30:01, 08/04/08 00:50:01
08/04/08 04:25:01, 08/04/08 04:30:01
08/04/08 20:20:01, 08/04/08 20:25:01
08/05/08
08/05/08 10:30:01, 08/05/08 10:35:01
My grep, sed, and awk skills are little rusty.
Anybody have any suggestions?
Thanks,
Chris