Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

My mac runs as a server with an dyndns ip. To work properly, it must be connected to the internet all the time. but unfortunately it seems that it is not connected a lot of times during the day. So I need a tool that checks i.e. once per minute if the mac is connected to the internet (i.e. by trying to reach google), and writes it to a log file.

Do you know something that can help out here? I need to check it on the machine, if itself has got internet. Mac OS 10.5. Thanks guys!!

share|improve this question

4 Answers 4

You can install nagios on a normal mac, they are Unix machines too :)

Would a script like this do ?

 #!/bin/bash
 LOG=/tmp/LOG
 rm -f $LOG
 while ( true );
 do 
  date >> $LOG;
  curl http://www.google.com/ > /dev/null  2>> $LOG
  sleep 60 ;
 done
share|improve this answer

Nagios will run on a Mac and it's open source / free!

http://www.macworld.com/article/134079/2008/06/nagios.html

Installing Nagios allows you to turn any Mac running Mac OS X Server into a network monitoring station able to notify you of both hardware and software problems on your server, usually before anyone else notices you. Nagios can use both e-mail and SMS to notify you of both problems and recovery from problems. (The latter is important, since it can often save you from a late-night remote access session.) Since Nagios requires Perl, Apache, SNMP and a few other things that Mac OS X Server either ships with, or that can be installed with ease, it’s a great way for any network administrator to better monitor their network.

share|improve this answer
    
thank you, that's nice. but i have just normal mac os x, no server. its a mac book that's always on ;) –  IRTFM Jul 28 '09 at 17:53
    
@IRTFM - You don't need OS X Server you can do it with OS X Client as well - you just may need to install an extra package. (Not having installed on client myself I don't know what package(s)) –  Chealion Jul 28 '09 at 22:37
    
Yes, it definitely does work fine on a MacBook. I set up my test installation that way before moving it to a server. –  John Gardeniers Jul 28 '09 at 23:07

Nagios is overkill for this, IMHO. Also, one likely cause for this extened offline phases is missing network traffic, so your router goes offline.

This will be prevented by James' script above, which I would just slightly modify to avoid downloading the google page every 60 seconds.

Just replace the curl google.com line witht the following

ping -c1 -t 5 www.google.com > /dev/null
if [ "$?" = "0" ]; then
    echo "I am online" > $LOG
else 
    echo "Boo, the internet is broken, google doesn't answer" > $LOG
fi

or, if you only want to log offline phases, modify the complete script like so:

#!/bin/bash
LOG=/tmp/internetlog
rm -f $LOG
while ( true );
do 
   ping -c1 -t 5 www.google.com > /dev/null
   if [ "$?" -gt "0" ]; then
       echo `date`  " I am offline" >> $LOG
   fi

 sleep 60 ;
done

This replace the curl call, which downloads the complete page from google with a single ping with a 5 second timeout, which is normally enough.

share|improve this answer

it may be a bit overkill but i'd recommend you to use nagios's plugins link text, using them you can then write a simple shell script to do what you need, or i guess the other alternative you can use simple ping also with shell script, it can be accomplished a lot easier with nagios plugins though.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.