LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-30-2006, 06:36 AM   #1
susee_sundar
LQ Newbie
 
Registered: May 2006
Posts: 3

Rep: Reputation: 0
Angry How to stop a real time process in a script


Hi All.,

I want to monitor the log file by grepping two patterns..
The log file is a real time one, which gets updated in every second..
i am using the following command to grep the pattern at its end..


$
$tail -f logfile | grep pattern1
[ctrl+c]
$tail -f logfile | grep pattern2
[ctrl+c]
$

But when I write a script to do it automatically
script content:-
!#/bin/sh
tail -f logfile | grep pattern1
tail -f logfile | grep pattern2
end

The script starts grepping the pattern1 fine..
But How can I make an interrupt fuction to stop it and make the shell to move to the next command..
If I Press CTRL+C

The Script ends and came back to the shell prompt..
If Anybody already faced the problem are knows the solution share me the same...
Waiting for the reply..


Regards
Suseendran .A


 
Old 05-30-2006, 06:57 AM   #2
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,499
Blog Entries: 2

Rep: Reputation: 68
Put the first command in background, then the second can start in parallel.
Code:
#!/bin/bash
tail -f logfile | grep pattern1 &
tail -f logfile | grep pattern2
 
Old 05-30-2006, 07:10 AM   #3
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,499
Blog Entries: 2

Rep: Reputation: 68
of course, if logfile is the same, you can search for several patterns in one single command
Code:
tail -f logfile | grep -E "pattern1|pattern2|pattern3"
 
Old 05-30-2006, 07:17 AM   #4
susee_sundar
LQ Newbie
 
Registered: May 2006
Posts: 3

Original Poster
Rep: Reputation: 0
The operation it is doing is fine..

But the hidden job is not getting killed even after the end os script..

i didnt get my prompt back and the grep pattern is displayed continuously for the hidden command.

regards
Suseendran .A
 
Old 05-30-2006, 07:20 AM   #5
susee_sundar
LQ Newbie
 
Registered: May 2006
Posts: 3

Original Poster
Rep: Reputation: 0
tail -f logfile | grep -E "pattern1|pattern2|pattern3"

Thank YOU for the Code
It is working fine.....

Regds
SUSEENDRAN .A
 
  


Reply



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
Stop Startup Process easyE Linux - General 2 05-03-2005 05:37 PM
Stop boot script at boot time!! kmiles2 Linux - Newbie 1 02-23-2004 10:04 PM
which process are safe to stop dkc_ace Linux - General 9 02-18-2004 03:09 PM
how to stop a process? frostmagic Programming 14 12-05-2003 11:02 AM
rc.d with K to stop the process... psyklops Linux - General 1 10-18-2003 01:14 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:18 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
Open Source Consulting | Domain Registration