Simple Script looking for Hard Coded Variables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simple Script looking for Hard Coded Variables
# 1  
Old 07-21-2009
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?

Code:
#!/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

Last edited by vgersh99; 07-21-2009 at 03:16 PM.. Reason: code tags, PLEASE!
# 2  
Old 07-21-2009
You don't need eval, 1 parse is enough.
Code:
#!/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"

# 3  
Old 07-21-2009
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 [code] and [/code] 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
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk file to read values from Db2 table replacing hard coded values

Hi, I want to replace a chain of if-else statement in an old AWK file with values from Db2 table or CSV file. The part of code is below... if (start_new_rec=="true"){ exclude_user="false"; user=toupper($6); match(user, "XXXXX."); if (RSTART ==2 ) { ... (9 Replies)
Discussion started by: asandy1234
9 Replies

2. Shell Programming and Scripting

Running a script with multiple variables like 25 variables.

Hi All, i have a requirement where i have to run a script with at least 25 arguements and position of arguements can also change. the unapropriate way is like below. can we achieve this in more good and precise way?? #!/bin/ksh ##script is sample.ksh age=$1 gender=$2 class=$3 . . .... (3 Replies)
Discussion started by: Lakshman_Gupta
3 Replies

3. Programming

How to select option for binary coded value?

Hello everybody, I looking for advice. I'm trying to decode a binary file. Some parameters are "Binary coded", that means that if a byte in hexadecimal is "0A", then in binary is 00001010. So, to decode this Byte I need to refer to the table below (depending the value in binary format, the... (2 Replies)
Discussion started by: Ophiuchus
2 Replies

4. UNIX for Dummies Questions & Answers

Simple example for soft and hard links

Hai, give me a simple example for soft and hard links. this will work for soft link ?? ln -s (2 Replies)
Discussion started by: Ramesh M
2 Replies

5. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

6. Shell Programming and Scripting

Simple unix variables in script

I'm creating a script that asks a user for a variable ex read filename; read numberinput; I also have a bunch of files named file.0 file.1 ... file.55 I'm trying to delete all files (if they exist) about file.$numberinput. Can someone help me out on how to include the variable as part... (6 Replies)
Discussion started by: jenix4545
6 Replies

7. Shell Programming and Scripting

Simple question (for you guys, hard for me)

I am trying to exit this script by cd'ing into a particular directory. #!/bin/bash /opt/xxx/xxx/d2h $1 fname=$( /opt/xxx/xxx/d2h $1) cd /opt/xxx1/xxx1 find . -name '*'$fname'*' -ls cd /opt/xxx1/xxx1 Upon execution, it returns to my home directory (where I am running this script from. ... (3 Replies)
Discussion started by: BkontheShell718
3 Replies

8. UNIX for Dummies Questions & Answers

Get enviroment variables into AWK, but not quite that simple!

Hi, I have a script which loops through a file and based on the fields in the file does certain things. I'm just testing the final version and come up against a problem. One of the things is to copy files, so the line in the release.file would look like this. COPY my_file $COPY_DIR 777 ... (1 Reply)
Discussion started by: m1l
1 Replies
Login or Register to Ask a Question