permanent log monitoring and leaving the console

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting permanent log monitoring and leaving the console
# 1  
Old 08-31-2009
permanent log monitoring and leaving the console

Hello, I'd like to create a small application which would monitor one important log on our Solaris 10 environment.
So far, I createad a script which does the monitoring, and I though through nohup it would become one of the permanent running processes.

>nohup &
[1] 3139
> more
if [ ! -f ${LOGDIR}/extracted_errors.log ]
then touch ${LOGDIR}/extracted_errors.log

tail -f application_common.log |
while read -r line
echo ${line} | grep 'ALERT' | grep 'first_application' | grep 'SourceError' >> /dev/null
if [ $? = 0 ]
echo "Logged at:"`date '+%h %d %H:%M:%S'`"1st Application failure" >> ${LOGDIR}/extracted_errors.log

echo ${line} | grep 'ALERT' | grep 'second_application' | grep 'SourceError' >> /dev/null
if [ $? = 0 ]
echo "Logged at:"`date '+%h %d %H:%M:%S'`"2nd Application failure" >> ${LOGDIR}/extracted_errors.log

Now, my problem is, it runs and does what I want, but how can I stop it?
When I want to exit the system (and leave the monitoring script running), it's not allowing me to leave. The only way how to leave, is to kill the tail -f process for other terminal connectionSmilie
What am I doing wrong?
Any help appreciated...
Thank you in advance.

# 2  
Old 08-31-2009
The problem is the "tail -f". This ties you down.

Try using "wc -l" on the log and keeping a record in a "previous lines count" file. Then sleep and calculate the number of lines by which the log has grown and "tail -<lgrowth>" the log if it has grown. Then save the current line count, sleep for a period and repeat the test. Within this loop test for a "time to exit" file and exit when this file exists.
Obviously such a script needs a "first time" condition.

Hope this makes sense.
# 3  
Old 08-31-2009

Have you tried:

nohup tail -f ...

# 4  
Old 08-31-2009
Hmm cfajohnson. How does the o/p stop the process without using kill ?
# 5  
Old 09-09-2009

Thank you guys for your help.
wc -l wouldn't work too well, because old datas from the log are backed up (so there would have to be some IFs...)
Meanwhile I had a lot of other job and now when I came back to this problem I found a solution, I created a small, which adds some texts like 'You should STOP' at the end of application_common.log, and then let the main script in while statement do following test:

echo ${line} | grep 'You should STOP' >> /dev/null
if [ $? = 0 ]
echo "Logged at:"`date '+%h %d %H:%M:%S'`"The monitor is being shut down" >> ${LOGDIR}/extracted_errors.log
exit 0

This works fine.. so farSmilie
So if anybody would have the same problem, this could be a soultion for you too.Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Output to console and to log

I have a menu based script where user will select different action via displayed menu. I want to log all the action or say whatever displayed on screen to a log file and want to achieve with in the same script. i tried named pipe as below.. logfile=mylogfile mkfifo ${logfile}.pipe... (3 Replies)
Discussion started by: vidyadhar85
3 Replies

2. Solaris

Can not log onto console

Hi, I have been trolling thorugh vast numbers of information but have not yet found a solution to my problem. I am unable to log onto my servers console and I can not explain whats going on. I am running Solaris 10 and have a console connected to it via a kvm switch. I am able to see the... (2 Replies)
Discussion started by: philjt88
2 Replies

3. Shell Programming and Scripting

log monitoring

Hi All; I have a log file(dynamic) which i need to monitor; the format of the log file is as follows #Session ID STATUS The status can be one of the three /starting ;/loading ;/success Example #Session ID STATUS ABC /started.html XYZ /started.html ABC /loading.html ABC... (2 Replies)
Discussion started by: maverick_here
2 Replies

4. Red Hat

Cannot log from console login

Hello All, I'm facing the following problem: On a specific server I have installed Red Hat ES 4.5 and everything seems ok. But after a specific reboot, when the login prompt on the console, I put the root password and I canīt log on. It is strange for me due to if y try to log on using SSH I... (1 Reply)
Discussion started by: mig28mx
1 Replies

5. UNIX for Dummies Questions & Answers

Console Log in..

Hi, Can anubody tell me how to log in to a remote server through console? Your help is appreciated.. (5 Replies)
Discussion started by: Amol21
5 Replies

6. Shell Programming and Scripting

Monitoring log file

Hi, I ned to monitor the tomcat log file called "catalina.out" for "Out of memory" error. the script should monitor this file and send us the mail as soon as it finds the string "Out of memory" in the file. can ypu suggest me which is the best way to do this? (4 Replies)
Discussion started by: shivanete
4 Replies

7. Windows & DOS: Issues & Discussions

Log monitoring in windows

Hi, I'd like to know if there is a way to monitor a log file conitnuously for one or more strings and if found, send an alarm. It should also take care not to inlcude the old log file entries. Thanks. (2 Replies)
Discussion started by: er_ashu
2 Replies

8. Shell Programming and Scripting

Log Monitoring through Perl

Hi, I am new to perl. I want to write a perl script to monitor logs. Where i want to monitor exceptions logged or any kind of error strings. I have a dir(On Solaris) with multiple log file which keeps rolling to .gz file after some time in that same dir. These logs files size keeps on... (0 Replies)
Discussion started by: solitare123
0 Replies

9. UNIX for Dummies Questions & Answers

Console Log

Does anyone know how to redirect any messages sent to /dev/console to a file. Thanks in advance. (4 Replies)
Discussion started by: kdreaves
4 Replies

10. UNIX for Dummies Questions & Answers

log monitoring

Hi there, I have an application runnig on HP_UX which logs critical mesages to a log file. What I would like to do is tail the log file and report on new messages. Easy....I here you say. The log file is continuing to be written to and the check scritp will be executed from cron. I was... (2 Replies)
Discussion started by: nhatch
2 Replies
Login or Register to Ask a Question