LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-28-2009, 05:18 PM   #1
threezerous
Member
 
Registered: Jul 2009
Posts: 89

Rep: Reputation: 15
grep and email


I have an application log which continues to get appended. I would like to grep the log for a string and if it finds the string, I would like an e-mail to be sent out.

I have the command for grep and for e-mail. But not sure how I can join them. I plan to put this is in a cron job which runs daily morning at 09:00 am.

grep -i "Error inserting selected objects"
echo "Error in import script - Auto Generated Mail DO NOT REPLY" | mailx -s "Error in import script...Contact Administrator" 'abc@xyz.com'

So the administrator and other users know that the process might have failed sometime during the night.

Once the error is noted, the administrator manually stops the script, fixes the error, cleans out the log file and restarts the script.

Is there a way to send an e-mail if the grep command is successful?

Thanks in advance.
 
Old 07-28-2009, 05:25 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
just join the two commands together with &&
 
Old 07-30-2009, 04:25 PM   #3
threezerous
Member
 
Registered: Jul 2009
Posts: 89

Original Poster
Rep: Reputation: 15
Thanks much...that worked.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to understand pipes - Can't pipe output from tail -f to grep then grep again lostjohnny Linux - Newbie 15 03-12-2009 11:31 PM
Script to find, grep and email basisvasis Programming 3 09-13-2008 01:23 PM
how to grep multiple filters with grep LinuxLover Linux - Enterprise 1 10-18-2007 08:12 AM
Grep Syslog - email shell script voodoofxz Linux - Newbie 1 09-06-2005 05:27 PM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 12:38 PM


All times are GMT -5. The time now is 12:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration