Add Me!Close Menu Navigation

My technical corner about Linux, Perl, programming, computer networks and network security

Add Me!Open Categories Menu

Basics of writing bash scripts, a simple network tester

Sometimes my internet connection is rubbish. Nowadays this scenario shouldn’t happen ever, but the real life is much brutal, as you know. Especially in Poland. So, my life insists me to do something strange things in my computers and here is an ordinary example.

I wrote my simple script some years ago to check quality of my internet connection. What does it mean here (quality)? So, a standard quality indicator is that the internet connection really works – very important.;-)

Another one – if the internet connection works, I must check quality of a routing. If the connection has as a rule near 50 ms to many hosts and suddenly I have 100 times slower, that indicates something is wrong. I don’t have to check numbers, if pings from my connection have 5 sec delay, I see this in normal use of my computer (watching movies isn’t pleasant then)
First test – I check that if I have working internet connection. In this case I use fping program.

### I use IP addresses here due to eliminate possible problems with a DNS service
IP_LIST = ( )
for i in "${HOSTLIST[@]}"
 ### How many tests...
 TESTS=`expr $TESTS + 1`
 CHECK=`fping $i | grep "is alive"`
 if [ -z "$CHECK" ];
  ### And how many problems...

if [ "$TESTS" -eq "$PROBLEMS" ];
 ### Problem with an internet connection - do something
 ### For example
 /etc/init.d/network restart

Second test checks routing.

### I assume that I have set $SOMEFILE_LOG
### List of hosts which are always work ;-)

for i in "${HOSTLIST[@]}"
 ping -c5 $i >> $SOMEFILE_LOG

Now, my script will do few tests and results will be written to the $SOMEFILE_LOG


It’s simple and you may add this to the crontab service. Afterwards, you will have many reports about state of your internet connection.

Leave a Reply

You must be logged in to post a comment.