Script to find string & email


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to find string & email
# 1  
Old 05-10-2012
Script to find string & email

Hi

I have a query that some of you may be able to help me with if poss? I'd appreciate it very much.

I've got a few log files, that I would like to search for a string. When the string is found, i'd then like to email out the line/sting.

If not found, i'd like to email out 'no found' etc.

so i've been wrecking my brains reading books etc. (i'm a complete beginner!)

anyhow, can anyone help/expand on this:

cd /export/home # so 1st command moves to where log files are
awk '/string_searching_for_here/' log_file_names* |mailx -s "subject_of_email" toemailaddress@test.com


this sort of works. I'm not sure how to then send an email if nothing is found.

I take it i should use the 'if' etc?

thanks
# 2  
Old 05-10-2012
Code:
grep "pattern" log_file_names* > /dev/null &&  grep "pattern" log_file_names*| mailx -s "subject_of_email" toemailaddress@test.com || (echo "Nothing Found" | mailx -s "subject_of_email" toemailaddress@test.com)

# 3  
Old 05-10-2012
thank worked a treat! thank you very much!!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to find a file with a specific pattern for current sysdate & upon find email the details?

I need assistance with following requirement, I am new to Unix. I want to do the following task but stuck with file creation date(sysdate) Following is the requirement I need to create a script that will read the abc/xyz/klm folder and look for *.err files for that day’s date and then send an... (4 Replies)
Discussion started by: PreetArul
4 Replies

2. Shell Programming and Scripting

Using Grep & find & while read line in a script

Hello people! I would like to create one script following this stage I have one directory with 100 files File001 File002 ... File100 (This is the format of content of the 100 files) 2012/03/10 12:56:50:221875936 1292800448912 12345 0x00 0x04 0 then I have one... (0 Replies)
Discussion started by: Abv_mx81
0 Replies

3. Shell Programming and Scripting

Script to find & replace a multiple lines string across multiple php files and subdirectories

Hey guys. I know pratically 0 about Linux, so could anyone please give me instructions on how to accomplish this ? The distro is RedHat 4.1.2 and i need to find and replace a multiple lines string in several php files across subdirectories. So lets say im at root/dir1/dir2/ , when i execute... (12 Replies)
Discussion started by: spfc_dmt
12 Replies

4. Shell Programming and Scripting

Script to send email after comparing the folder permissions to a certain permission & send email

Hello , I am trying to write a unix shell script to compare folder permission to say drwxr-x-wx and then send an email to my id in case the folders don't have the drwxr-x-wx permissions set for them . I have been trying to come up with a script for few days now , pls help me:( (2 Replies)
Discussion started by: nairshar
2 Replies

5. Shell Programming and Scripting

Find a string using grep & print the line above or below that.

Hi All, Please tell me how can I Find a string using grep & print the line above or below that in solaris? Please share as I am unable to use grep -A or grep -B as it is not working on Solaris. (10 Replies)
Discussion started by: Zaib
10 Replies

6. Shell Programming and Scripting

PHP read large string & split in multidimensional arrays & assign fieldnames & write into MYSQL

Hi, I hope the title does not scare people to look into this thread but it describes roughly what I'm trying to do. I need a solution in PHP. I'm a programming beginner, so it might be that the approach to solve this, might be easier to solve with an other approach of someone else, so if you... (0 Replies)
Discussion started by: lowmaster
0 Replies

7. Shell Programming and Scripting

Find & Replace string in multiple files & folders using perl

find . -type f -name "*.sql" -print|xargs perl -i -pe 's/pattern/replaced/g' this is simple logic to find and replace in multiple files & folders Hope this helps. Thanks Zaheer (0 Replies)
Discussion started by: Zaheer.mic
0 Replies

8. UNIX for Dummies Questions & Answers

Find, Replace & Edit a string?

Is this something SED would be used for or can AWK do it? I have a string that I would like to chop bits out of and re-arrange some of the rest. Basically I want to change this: <log4j:event logger="webserver" timestamp="1240110840109" time="Sun Apr 19 04:14:00 BST 2009" level="INFO"... (4 Replies)
Discussion started by: Sepia
4 Replies

9. UNIX for Dummies Questions & Answers

cmd sequence to find & cut out a specific string

A developer of mine has this requirement - I couldn't tell her quickly how to do it with UNIX commands or a quick script so she's writing a quick program to do it - but that got my curiousity up and thought I'd ask here for advice. In a text file, there are some records (about half of them)... (4 Replies)
Discussion started by: LisaS
4 Replies
Login or Register to Ask a Question