LinuxQuestions.org
Review your favorite Linux distribution.
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 10-20-2011, 04:35 PM   #1
ktfreak
LQ Newbie
 
Registered: Nov 2010
Posts: 14

Rep: Reputation: 0
Getting an alert if string is found in file


Hi,

I want to write a small script which scans a logfile for an error message permanently and prints out a notification + timestamp every time the error message string is added new to the logfile.

I'm not sure if I can use a simple while loop and a simple expression to do that.

Can you help me?
thanks
 
Old 10-20-2011, 05:03 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 19,263

Rep: Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440
Quote:
Originally Posted by ktfreak View Post
Hi,

I want to write a small script which scans a logfile for an error message permanently and prints out a notification + timestamp every time the error message string is added new to the logfile.

I'm not sure if I can use a simple while loop and a simple expression to do that.

Can you help me?
thanks
No need to do this...look into using logwatch, which is designed exactly for such things.
 
Old 10-20-2011, 05:51 PM   #3
ktfreak
LQ Newbie
 
Registered: Nov 2010
Posts: 14

Original Poster
Rep: Reputation: 0
Thanks,

I'm afraid logwatch is not installed and unfortunately I don't have root permission in our enterprise linux environment (redhat) to install it. Is there any other option?

Last edited by ktfreak; 10-20-2011 at 05:55 PM.
 
Old 10-20-2011, 07:32 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,361
Blog Entries: 55

Rep: Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547
If you don't have root rights then the log file, if it resides in /var and has sane access permissions, will be inaccessible to you anyway. As far as an example goes something like
Code:
while read LINE; do [ "${LINE//error/}" != "${LINE}" ] && { echo 'Got one!'; }; done < <(tail -f /var/log/messages)
could do looking for the term "error" in /var/log/messages.
 
1 members found this post helpful.
  


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
how do i replace a text string in a file with a random string? (with sed etc) steve51184 Linux - Software 16 09-02-2010 12:05 PM
Shell scripting - Getting just directory string from file path string? arashi256 Programming 5 10-16-2009 09:21 AM
read string after specific string from a text file using C++ programing language badwl24 Programming 5 10-08-2009 06:41 AM
Shell Script: Delete lines til string found or until particular string. bhargav_crd Linux - General 3 12-21-2007 12:14 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:56 AM.

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