PDA

View Full Version : Help with getting values from a couple of lines of grep output.



musther
April 28th, 2007, 11:37 PM
I've currently got a loop looking like this:


for i in $( mountread | grep --regexp="/dev/hd" --regexp="/dev/sd" ); do
sudo tune2fs -l /dev/sda2 | grep --regexp="Mount count:" --regexp="Maximum mount count:"
done

It outputs these two lines (pure loop iteration):


Mount count: 15
Maximum mount count: 25


What I need to do is get those numbers into variables so that I can compare them with an if statement.


Thanks

raja
April 29th, 2007, 04:03 AM
Someone who know bash better may come along to help us better. However, I think the following should do what you want


mountcount=$(sudo tune2fs -l /dev/sda2 | grep --regexp="Mount count:" | tr -d "Mount count:")

if [ "mountcount" -le 20 ]
then
echo "mount count is smaller than 21"
fi

musther
April 29th, 2007, 06:54 AM
Thankyou, I need the tr command!