 |
 |
Log uptime of external link
|
 |
|
 |
|
Mac Enthusiast
Join Date: Jan 2001
Location: Leesburg, Virginia
Status:
Offline
|
|
I have the suspicion that our Comcast cable highspeed Internet connection is somewhat flakey. I thought, I'd write a cron job that will every 10 s or so pings a known external address (in this case, the gateway between Internet and the internal network at work, which is on a highly reliable T1 line) and log the result. Here's the command
Code:
echo `date` -- `ping -c 1 xx.xx.xx.34 | sed -n -e 's/.*0\%.*/up/' -e 's/.*100\%.*/down/' -e "/up/p" -e "/down/p"`
Output is of the form
Code:
Sun Jan 16 02:14:49 EST 2005 -- up
At a rate of once every 10 seconds, the cron job would write 138 kB per day to the log file. That won't work. But with a longer repetition period I won't catch the short glitches that might make VoIP a non-starter. The solution would be a variable repetition rate with short periods after the link was found to be "down", becoming successively longer, when it gets back up.
Perhaps a cron job won't be the best approach, and I'll have to teach myself flow control in bash scripting, in order to implement the scheme.
Nonetheless, I just wanted to throw the above command out there. Perhaps it's useful for others, perhaps someone might care to comment.
Dominik Hoffmann
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Jan 2001
Location: Leesburg, Virginia
Status:
Offline
|
|
Okay, cron can schedule any command with at most a frequence of once a minute.
However, when I have it run the command
Code:
echo `date` -- `ping -c 1 xx.xx.xx.34 | sed -n -e 's/.*0\%.*/up/' -e 's/.*100\%.*/down/' -e "/up/p" -e "/down/p"` >> /var/log/uptime.log
I find that uptime.log only contains lines like so
Code:
Sun Jan 16 02:57:00 EST 2005 --
Sun Jan 16 02:58:00 EST 2005 --
Sun Jan 16 02:59:00 EST 2005 --
Sun Jan 16 03:00:00 EST 2005 --
Sun Jan 16 03:01:00 EST 2005 --
Sun Jan 16 03:02:00 EST 2005 --
Sun Jan 16 03:03:00 EST 2005 --
Sun Jan 16 03:04:00 EST 2005 --
Sun Jan 16 03:05:00 EST 2005 --
Sun Jan 16 03:06:00 EST 2005 --
Sun Jan 16 03:07:00 EST 2005 --
It's as though the ping command is never executed. Is this a subtlety of echo?
Dominik Hoffmann
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Jan 2001
Location: Leesburg, Virginia
Status:
Offline
|
|
Originally posted by DominikHoffmann:
It's as though the ping command is never executed. Is this a subtlety of echo?
The answer to why the ping doesn't happen is in a response to another post.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Jan 2001
Location: Leesburg, Virginia
Status:
Offline
|
|
Originally posted by DominikHoffmann:
Code:
... sed -n -e 's/.*0\%.*/up/' -e 's/.*100\%.*/down/' -e "/up/p" -e "/down/p" ...
I have since found that I need to do the replacement of "100%" before doing the replacement of "0%", because, of course, "100%" matches the regular expression .*0\%.*, too. So, the correct sed portion of the command is
Code:
... sed -n -e 's/.*100\%.*/up/' -e 's/.*0\%.*/down/' -e "/up/p" -e "/down/p" ...
Dominik Hoffmann
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jun 2000
Status:
Offline
|
|
Okay, cron can schedule any command with at most a frequence of once a minute.
You could write a shell script and use the sleep command to have it run ping every few seconds.
|
|
Agent69
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|