2012-05-28

ping tool / debugging a server from afar

hello readers,

sometimes my server is unreachable for no apparent reason. The logs don't really give a clue and my only way of reaching it again is to restart it by sending it an automatic hardware reset.
Since I have no idea whether it is locked up, just unreable *from* the network or completly disconnected from the network I wrote a little script to log pings. This way I can see in the log if it tries to ping at all and if it tries, if it can reach the network from its side or not.
Now all I have to do is to wait for it to crash. Well, I mean, to hope for the script to be a useless effort since it will never crash again ... of course ... ;)

Here's the script:


#!/bin/bash
# filename: pinglog.sh
# set logging dir here
MYDIR=/var/log/ping
# here you can choose a different format, i.e. "$1.log"
# where $1 always is the hostname given to the script
MYFILENAME="$1"
echo `date +'%Y-%m-%d %H:%M: '` `ping -c1 $1 | head -n2 | tail -n1` >>\ $MYDIR/$MYFILENAME

and here's a line for you to enter in in the crontab, if you want it to ping&log every 5minutes:

*/5 * * * * /some/directory/pinglog.sh some.server.com


I know it's not something big or difficult, but sometimes big problems need low-tech solutions. Also small scripts like these can be a good alternative to installing big software packages like nagios, if you don't really need them.

No comments:

Post a Comment