Shell Script Problem
Hi there... I'm not a good scripter (as will be obvious here lol)... trying to build a simple script that will:
Generate a directory list, search inside of each directory for a specific file (if it exists), and then search that file for matching criteria. In this particular example I'm searching for specific IP addresses throughout 300+ apache access logs. Here's what I have created and I'm having a problem that I'm sure will be obvious..;) #!/bin/sh for dir in '/bin/ls /home/httpd/vhosts' do find /home/httpd/vhosts/$dir/statistics/logs/ -name access_log -exec \ egrep -il "193.169" {} \; done Output breaks with the following: find: /home/httpd/vhosts//bin/ls: No such file or directory find: /home/httpd/vhosts/statistics/logs/: No such file or directory So it seems that the dir variable isn't passing two lines down or am I missing something here? Any and all suggestions/help is most welcome. Paul |
First thing I notice is that you are not using "grave marks" in
Code:
'/bin/ls /home/httpd/vhosts' Personally, I would try a recursive grep looking for that IP. |
recursive grep
Thank you for the reply ... I"m searching and trying to find a way to have a recursive grep output the directory/filename where it finds a match?
This was what I started with originally was trying to recursively grep out a match from all files in a series of subdirectories but when it goes find a match there was no way (that I could find) to output the full path... I must be missing something? ;) Paul |
Depends a bit on how neat you want your output to be.
First off, change the first line in your script to: Code:
for dir in $(/bin/ls /home/httpd/vhosts) Since you have $dir in the middle of you path, using a for loop is not such a bad idea. Using grep -H makes grep print the file name it is processing including the directory. jlinkels |
Not sure if I understand your problem correctly, but this might be what you want:
Code:
#!/bin/sh The same as above can be achieved much simpler by: Code:
grep "193.169" /home/httpd/vhosts/*/statistics/logs/* Code:
for FILE in /home/httpd/vhosts/*/statistics/logs/access_log; do Code:
for DIR in '/bin/ls /home/httpd/vhosts'; do |
Quote:
Code:
grep -rl |
Just to expand a bit:
Code:
[matonb@dev ~]$ grep -rl "193\.169" /tmp Code:
[matonb@dev ~]$ grep -rl "193.169" /tmp Code:
193.169 Code:
193x169 |
All times are GMT -5. The time now is 07:47 PM. |