If i wanted to extract the number of collisions from the eth0 section of the ifconfig file and have the output placed in a variable how would i do this?
I can get the output displayed using:
/sbin/ifconfig eth0 | grep "collisions"
What command would i now use to place the output in a variable known as "Collisions"?
The followmnmg will do what you are after:
COLLISIONCOUNT=`/sbin/ifconfig eth0 | grep "collisions"`
COLLMAX=99
if [ ${COLLISIONCOUNT} -gt ${COLLMAX} ] then
echo "Collision count is greater than ${COLLMAX}!"
else
echo "Collision count is less than than `expr ${COLLMAX}+1`!"
fi
It is the ` characters that run what is inside them and cause the output to be passed to the variable before the equals sign.