I'm working on a script that gets information from a log called ip.txt and contains the following:
192.168.7.x OK
192.168.9.x OK
192.168.5.x OK
Looking for help, I managed to make it print a status depending on the file if all the IPs have "OK" then this "OK" if any of the IP has something other than "OK" then it is wrong.
filename="/home/ip.log"
while read -r line
do
readline=$line
if [[ $readline = *"OK"* ]]
then
result_output="BIEN"
else
result_output="MAL"
fi
done < <(tail -n "+2" $filename)
echo $result_output
Now I would like to make that when the output is "BAD" determine how many lines were like a counter, for example when printing something like this "5 BAD"
What I did was add:
filename="/home/ip.log"
while read -r line
do
**var=0**
readline=$line
if [[ $readline = *"OK"* ]]
then
result_output="BIEN"
else
result_output="MAL"**"$((var++))"**
fi
done < <(tail -n "+2" $filename)
echo $result_output
But this is the only thing he does is print is "0" at the end of MAL