Help adding a key word search to my script

Hello:

I need help adding a key word search to my bash script. I have the following script. My boss whats the user to be able to add a search word e.g. unknown failures for the script to search the logs through and find the instances. I had originally done it so it grepped for unknown failures, but now he wants it to accept a key word. Any help is appreciated. Thanks in advance.

[code]
#

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

Did you mean run time search key word?

Get the word and search as variable.

grep "$search_word_input" filename

Also, there are too many UUOC in the code, take a look at them

cat /var/log/messages |grep -i '[audit demon stops]'>>/tmp/logproblems.txt
<can_be_written_as>
grep -i '[audit demon stops]' /var/log/messages >> /tmp/logproblems.txt

cat /var/log/messages  |grep -i unknown |wc -l>>/tmp/logproblems.txt
<can_be_written_as>
grep -ic unknown /var/log/messages >> /tmp/logproblems.txt

cat /var/log/secure |grep -i 'password check failed'|awk '{print $0}'
<can_be_written_as>
awk ' /password check failed/ {print $0}' /var/log/secure

This is what I want to do.

Get the word and search as variable.

So that I can have an option in the menu for the person to enter a keyword and do the search on that keyword. I think it needs to be a variable or something like that. I would appreciate any help doing this. Thanks.

I guess that is what I had posted.

Get the input using " read "
and use the above grep

I guess my lack of scripting combined with my flu are making me dizzy. If I add a line to the menu, such that is says input here your search criteria. How then do I pass it to the read?
echo " 6) Input your search criteria here"
6) echo "read"
;;

it's something like :

echo  "   6) Input your search criteria here" 

read var_1;

;;

grep "$var_1" file_name.txt

This works great. Thank you all so much for your help.

  6\)    echo "enter your search criteria here"
        read var_1;
        cd /home/demo/current_release/logs/current
        grep -i "$var_1" *.log|sort -u |more
        ;;

Sorry, I have one more urgent request. My manager has asked me how to add a time variable. In other words, the user of the script must be able to choose a time, say 10-01-09 to 10-03-09. Can you please help me? He's asked for it by Close of business today. I'm thinking, why can I just use the line above,

6) echo "enter your search criteria here"
read var_1;
cd /home/demo/current_release/logs/current
grep -i "$var_1" *.log|sort -u |more
;;
MAYBE

7)echo "enter your time criteria here"
read var_2;
cd /home/demo/current_release/logs/current
grep -i "$var_1" *.log|grep -i "$var_2"|sort -u |more

Would that work do you think?

---------- Post updated at 12:45 PM ---------- Previous update was at 12:18 PM ----------

Last thing I'd like to mention is the date format of the log files are odd. It's like
demo-name.2009_320_123456.999.log The key thing here is 2009_320 where its year 2009 and the 320th day of the year. Any help would be greatly appreciated.

---------- Post updated at 03:14 PM ---------- Previous update was at 12:45 PM ----------

I got the date column to work, but now I've been asked to add the option to change the path? Anyone know how to do that in an option? Thanks.