ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Welcome to LinuxQuestions.org, a friendly and active Linux Community.

You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!

Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.

If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.

Having a problem logging in? Please visit this page to clear all LQ-related cookies.

Introduction to Linux - A Hands on Guide

This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.

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..

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?

This outputs the full path of all files in these directories that contain '193.169'.
The same as above can be achieved much simpler by:

Code:

grep "193.169" /home/httpd/vhosts/*/statistics/logs/*

You also can do something like this:

Code:

for FILE in /home/httpd/vhosts/*/statistics/logs/access_log; do
if grep "193.169" $FILE >/dev/null; then
echo "The file $FILE contains 193.169!"
fi
done

or this:

Code:

for DIR in '/bin/ls /home/httpd/vhosts'; do
for FILE in /home/httpd/vhosts/$DIR/statistics/logs/access_log; do
if grep "193.169" $FILE >/dev/null; then
echo "The file $FILE contains 193.169!"
fi
done
done

It all depends on what exactly you want to do. Just play arround with it and see what it does.

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?