Simple Script looking for Hard Coded Variables

Hi Guys

Looking for a little help with a script to grep all files looking for hard coded variables - ie its IP address... so we know which files to look at before an IP change...

This is what I have - but it seems to loop and never end...

Any better suggestions?

#!/usr/bin/ksh
#simple script to grep for the IP of the host in any file
echo "Enter the IP address you want to find"
read IP
eval log=/tmp/ipfind.out.$IP
tput clear
eval echo "greping all files for $IP"
echo "This will take a considerable amount of time to complete..."
eval echo "Scripts logs to /tmp/ipfind.out.$IP"
cd /
grep -r $IP * 1>$log 2>/dev/null
eval echo "Script complete. please check /tmp/ipfind.out.$IP"
exit

Any help really appreciated...

r

You don't need eval, 1 parse is enough.

#!/usr/bin/ksh
#simple script to grep for the IP of the host in any file
echo -n "Enter the IP address you want to find:"
read IP
log=/tmp/ipfind.out.$IP
echo "greping all files for $IP"
echo "This will take a considerable amount of time to complete..."
echo "Scripts logs to /tmp/ipfind.out.$IP"
# IP include ., which is special char for regexp, so you need change . -> \.
IP="${IP//./\\.}" 
# find regular files and grep IP, take time, output only filenames which include $IP
find / -type f -exec grep -l "$IP" {} \;  > $log  2>/dev/null
echo "Script complete. please check $log"

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums