LinuxQuestions.org
Help answer threads with 0 replies.
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-08-2009, 11:21 PM   #1
elainelaw
Member
 
Registered: Jan 2008
Posts: 258

Rep: Reputation: 30
Script to check the string


In my system , there is a program will generate a log to the text file , this program will run times per day , can advise if I want to check the text file , if the text file have a string "Uuable to run program" , then send mail to me , can advise what can i do ? thx
 
Old 10-08-2009, 11:39 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
You could try logwatch http://linux.die.net/man/8/logwatch.
The main question is whether you want to do this in batches eg once per day, in which case logwatch should do nicely. If you want real-time, I don't know if logwatch can do that.
If not, you could possibly amend the script that attempts to run the invalid prog to email you immediately.
Another option is to find or write a prog to continuously tail the logfile, looking for such errors eg the perl module http://search.cpan.org/~mgrabnar/Fil...0.99.3/Tail.pm is designed to do just that.
 
Old 10-09-2009, 04:40 AM   #3
elainelaw
Member
 
Registered: Jan 2008
Posts: 258

Original Poster
Rep: Reputation: 30
thx reply ,

instead of use logwatch , as I tried to setup logwatch ,but it is too difficult to me , is there any method ( script ) do it ? please advise .
 
Old 10-09-2009, 04:57 AM   #4
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by elainelaw View Post
thx reply ,

instead of use logwatch , as I tried to setup logwatch ,but it is too difficult to me , is there any method ( script ) do it ? please advise .
Write a script that does something like this:

1. Read recent log entries and check for the desired text:

Code:
if tail -n 50 < logfilename | grep -q "Unable to run program"
then
   # do something here
fi
(choose how many lines you need to read -- 50 is just an example)

2. In the above "do something here" position, send an e-mail to a specified recipient:

Code:
echo “program so-and-so failed to run at `date`” | mail -s “Program Launch Failure” user@domain.com
3. Run the sequence above periodically from cron.

It's really easy to set up something like this.
 
Old 10-11-2009, 09:47 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
The fiddly bit will be ensuring you don't pickup the same error more than once ie in subsequent checks. You need to know what line the last known msg was on, hence the Perl soln I mentioned.
If you make a note of the line num in a temp file, that could work.
 
  


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
To check whether a string is palindrome or not som_kurian Programming 9 12-29-2007 02:56 AM
Shell Script: Delete lines til string found or until particular string. bhargav_crd Linux - General 3 12-21-2007 12:14 AM
Bash script to check the input string length fjkum Programming 3 06-30-2007 09:43 PM
How can I check if there slash in the end of string in bash if? nadavvin Programming 5 01-27-2007 03:41 AM
howto check string is integer? ygloo Programming 4 10-14-2006 12:09 PM


All times are GMT -5. The time now is 03:12 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