Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > Log uptime of external link

Log uptime of external link
Thread Tools
Mac Enthusiast
Join Date: Jan 2001
Location: Leesburg, Virginia
Status: Offline
Reply With Quote
Jan 16, 2005, 01:31 AM
 
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
Reply With Quote
Jan 16, 2005, 02:07 AM
 
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
Reply With Quote
Jan 18, 2005, 10:34 PM
 
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
Reply With Quote
Jan 22, 2005, 08:47 AM
 
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
Reply With Quote
Jan 26, 2005, 12:28 PM
 
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
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 07:06 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2