Search and email


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search and email
# 1  
Old 07-17-2012
Tools Search and email

Hi,

I have logs where I have to check this logs for the particular string for every 3 hours and send email alert if that string found in that log

Did anybody have the shell script to do this.

Smilie
# 2  
Old 07-17-2012
What did you try so far? Where are you stuck?
# 3  
Old 07-18-2012
Thanks Issue resolved

Last edited by manju98458; 11-12-2012 at 10:05 AM.. Reason: code tags, see PM!
# 4  
Old 07-18-2012
Quote:
Originally Posted by manju98458
Hi,

Not yet started because the log file is huge and everyday I have to monitor this log at every 3 hour once and if the string found it should
send an email.

---------- Post updated 07-18-12 at 04:59 PM ---------- Previous update was 07-17-12 at 09:57 PM ----------

#!/bin/bash
ECHO=/bin/echo
> /tmp/temp3.txt

String=`tail /var/logs/messages | grep -n " API Failure" | awk '{print $10}'` > /tmp/alert.txt
This wont work ...
if [ "$String" != "API Failure" ]
this should be ==
then
STATUS="Info"
$ECHO "From: xxx@test.com" >> /tmp/temp3.txt
$ECHO "Subject: API Failure - $DATE " >> /tmp/temp3.txt
$ECHO "Dear Team" >> /tmp/temp3.txt
$ECHO " " >> /tmp/temp3.txt
$ECHO "API Failure !" >> /tmp/temp3.txt
$ECHO " " >> /tmp/temp3.txt
$ECHO "-----------------------------" >> /tmp/temp3.txt
$ECHO `hostname` >> /tmp/temp3.txt
$ECHO "-----------------------------" >> /tmp/temp3.txt
$ECHO "Regards," >> /tmp/temp3.txt
$ECHO "Support admin" >> /tmp/temp3.txt
/usr/sbin/sendmail -f xxx@xp.com yyy@.bpcom < /tmp/temp3.txt
fi

Here is my script please advise me , if any code change. My ultimate aim is to
grep the log 3 hours before from the time and it should check for the error
if found it should send an alert email.
# 5  
Old 07-18-2012
I have modified the script Pamu, how to grep 3 hours data in the script itself , say 9 AM I have to check the log it should check the logs before
9 AM and generate it.
# 6  
Old 07-18-2012
Could you please paste some lines from your log file..
# 7  
Old 07-18-2012
Due to security issue , I cannt able to paste the logs please
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Search email addresses using grep command

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Let's say if we have a file with a lot of information. For example: iiadam otterhedgehog kayleigh... (2 Replies)
Discussion started by: ForeignGuy
2 Replies

2. Shell Programming and Scripting

Getting email output in single line with out space in email

I have tried below email method and i am getting every thing in single line . i have put echo to provide space, but it is not helping my code ( echo "From: $FROM" echo "To: $MAILTO" echo "CC: $CC" echo "Subject: $SUBJECT" echo "MIME-Version: 1.0" echo 'Content-Type: multipart/mixed;... (6 Replies)
Discussion started by: mirwasim
6 Replies

3. UNIX for Dummies Questions & Answers

Search string and send email

Hi All, I need script which should search for the "reason code" and it should send mail with its preceding line as well as the line below it.(first line before it and line after it) I used below script but it is printing the whole lines inside it, your help is appreciated: cd... (3 Replies)
Discussion started by: rockingvj
3 Replies

4. Shell Programming and Scripting

Awk to search for sting in lines and then email.

I'm trying to use awk in a script to search for a string number in a plist file. basically its a plist that records the bandwidth usage, and if the number is greater than 3GB which is equals 3221225472 bytes, it will send me an alert by email. here is the file: =<?xml version="1.0"... (4 Replies)
Discussion started by: ivaldiz
4 Replies

5. Shell Programming and Scripting

search file for value greater than 'n' on each line and email

Hi, I need to write a script that will read each line of a CSV file, look for values greater than x seconds and email an alert. For the first part, I have one CSV per day, each line in the CSV has comma separated values. There are a total of 8 fields per line separated by commas. 6th and 7th... (3 Replies)
Discussion started by: ssid
3 Replies

6. Shell Programming and Scripting

Using top command to email if process is exceeding 25% and sending an email alert if so

This is my first time writing a script and Im having some trouble, Im trying to use the top command to monitor processes and the amount of CPU usage they require, my aim is to get an email if a process takes over a certain percentage of CPU usage I tried grep Obviosly that hasnt worked, Any... (8 Replies)
Discussion started by: jay02
8 Replies

7. UNIX for Dummies Questions & Answers

new to ldap, send email to a ou or group, and see a list from email client

hi, i'm running openldap on ubuntu 10.04, creating new items with apache directory studio (windows version). i use the ldap just as an address book to our small office (email clients are windows live mail 2009, 2011, microsoft outlook 2007 and 2010). a. i cant see a list of the contacts,... (0 Replies)
Discussion started by: V4705
0 Replies

8. Solaris

Send an email from Solaris using Linux email server

Hello everyone I have a problem and I need your help: I have a Solaris 10 and Solaris 8 UNIX Servers, and Linux Centos4 as email server. I need send an email from Solaris servers preferably using Centos4 email server. I have no mail service configured in my Solaris computers (1 Reply)
Discussion started by: aflores
1 Replies

9. Forum Support Area for Unregistered Users & Account Problems

Changed email, now I can't post/search

I decided to change my email address to the one I have at work and now I cannot post or search. I'm guessing that there is a confirmation email that was sent that may have been blocked by the mail server. Can you tell me of a way to change my email address back to my personal one now that I... (1 Reply)
Discussion started by: douknownam
1 Replies

10. UNIX for Advanced & Expert Users

Unable to send eMail from a UNIX-Host ( using mailx ) to a Outlook-email-addres(Win)

Hi A) I am able to send eMail using mailx from a UNIX ( solaris 8 ) host to my Outlook-email-ID : FName.Surname@Citigroup.com ( This is NOT my actual -eMail-ID). But in Outlook the "From :" eMail address is displayed as " usr1@unix-host1.unregistered.email.citicorp.com " .i.e the words... (2 Replies)
Discussion started by: Vetrivela
2 Replies
Login or Register to Ask a Question