I'm trying to grep through a directory and find files that have patterns to tell basically if that account is using mysql or oracle, and various other things. So far I have this, which works, but will print multiple files if it doesn't leave the current directory which I can see by the code that it makes sense. My question is, is there a way to stop a recursive grep after it is found once in a file, and prevent it from searching through the next file, similar to grep -m 1.
Code:
for j in `ls /var/www`; do
# Set variables as false
a=1
b=1
c=1
echo ""
echo "-------------$j--------------"
# Start loop through files
for i in `ls /var/www/$j`; do
if [[ $a == 1 && $b == 1 && $c == 1 ]]; then
grep -wrl "test1" /var/www/$j/$i && a=0 && echo -e "\ttest1 found"
grep -wrl "test2" /var/www/$j/$i && b=0 && echo -e "\ttest2 found"
grep -wrl "test3" /var/www/$j/$i && c=0 && echo -e "\ttest3 found"
elif [[ $a != 1 && $b == 1 && $c == 1 ]]; then
grep -wrl "test2" /var/www/$j/$i && b=0 && echo -e "\ttest2 found"
grep -wrl "test3" /var/www/$j/$i && c=0 && echo -e "\ttest3 found"
elif [[ $a == 1 && $b != 1 && $c == 1 ]]; then
grep -wrl "test1" /var/www/$j/$i && a=0 && echo -e "\ttest1 found"
grep -wrl "test3" /var/www/$j/$i && c=0 && echo -e "\ttest3 found"
elif [[ $a == 1 && $b == 1 && $c != 1 ]]; then
grep -wrl "test1" /var/www/$j/$i && a=0 && echo -e "\ttest1 found"
grep -wrl "test2" /var/www/$j/$i && b=0 && echo -e "\ttest2 found"
elif [[ $a == 1 && $b != 1 && $c != 1 ]]; then
grep -wrl "test1" /var/www/$j/$i && a=0 && echo -e "\ttest1 found"
elif [[ $a != 1 && $b == 1 && $c != 1 ]]; then
grep -wrl "test2" /var/www/$j/$i && b=0 && echo -e "\ttest2 found"
elif [[ $a != 1 && $b != 1 && $c == 1 ]]; then
grep -wrl "test3" /var/www/$j/$i && c=0 && echo -e "\ttest3 found"
fi
done
done