bash script report errors on interfaces

Hi, I need assistance with my script, I am basically quering the system for all of the active interfaces and then I am searching for all different types of errors on collisions, dropped packets overruns, carrier, frame, if any other number than zero appers it will send me an email. So far this is what I have, but I am getting errors.

The joint 1 file looks like
eth0 errors:1 dropped:0 overruns:0 carrier:0
eth1 errors:0 dropped:0 overruns:0 carrier:0

Thank you for your assistance.

Mike



#!/bin/bash
 
LIMIT="0"
SUBJECT="Network error on $hostname"
ADMINS=myemail@gmail.com
 
#The interface will be displayed
ETH=$(ifconfig | awk '/(eth)/ { print $1 }' | cut -d':' -f2 | head -4 > /root/eth)
 
TX=$(ifconfig | grep "TX packets" > /root/tx)
 
paste /root/eth /root/tx > /root/joint
 
COMPARE=$(awk '{print $1, $4, $5, $6, $7}' /root/joint | grep -Ev "TX|0" > joint1)            
 
if [ $COMPARE -ge  $LIMIT]
   echo "Error on interface
fi

Open in new window

dpoper1Asked:
Who is Participating?
 
dpoper1Connect With a Mentor Author Commented:
Hi, I need assistance please, here is my joint 1 output file

eth0 errors:1 dropped:0 overruns:0 carrier:0
eth1 errors:0 dropped:0 overruns:0 carrier:0


but I am still getting the following error

./scriptname.sh: line 22: [: too many arguments the line 22 is the if statement.

Thanx

LIMIT="0"
ERR22=$(cat /root/joint1 | awk ' { print $2 }' | cut -d':' -f2)
 
while true; do
   for file in $ERR22;do
        if [ $ERR22 -gt $LIMIT ];
        then
        echo "cat/root/joint1 |awk ' { print $1, $2 }' "| mail $SUBJECT $ADMINS
        fi
   done
done

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.