Bash script: Search for text in a web app

I started taking small steps into bash scripting with this little tool that help me find a lot of useful stuff in Vtiger, but it can be applyed to anything else with some little mods. This script finds files in Vtiger installation that contain the text requested. It is reporting on the file name and path and also highligsts the line than contains the text. So here is the script. Breakdown is below

The script

#!/bin/bash

echo What are we searching for?
read string

ignore=("/var/www/html/cache" "/var/www/html/storage" "/var/www/html/pdf")
for i in /var/www/html/* 
do
    if [[ ${ignore[*]} =~ "$i" ]]
    	then
		echo "omitting $i"
	else
		echo "searching in $i"
		find $i -type f -exec grep --color=always -H "$string" {} \;
    fi
done

The breakdown

So what we are doing here is displaying a message to user, taking a text input for a search string and providing the ignore list (top level folders like cache) in the array.

echo What are we searching for?
read string

ignore=("/var/www/html/cache" "/var/www/html/storage" "/var/www/html/pdf")

Next comes the loop that iterates through all the top level folders and checking if this folder is in the ignore array

for i in /var/www/html/* 
do
    if [[ ${ignore[*]} =~ "$i" ]]
    	then
		...
	else
		...
    fi
done

So if it is in the ignore list it should be ignored, obviously. We are just echoing

then
		echo "omitting $i"

But if it is not, then let’s search in it. And I kinda like interactivity so I prompt user about this action as well

else
		echo "searching in $i"
		find $i -type f -exec grep --color=always -H "$string" {} \;

And we are ready to use this one.

So this script has given me opportunity to fing all the things by variable name, or a css class or id… or just anything that helps you track for errors or points where you can modify things in the app.

Hope this script will also help you guys.

Rock On!
Roady