How to have my ksh script pause, until something appears in the logs.?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to have my ksh script pause, until something appears in the logs.?
# 1  
Old 04-11-2013
Question How to have my ksh script pause, until something appears in the logs.?

All,

Is there some way to have my KSH script pause, until the word "DONE!" appears in the logfile /logs/log.txt?

Difficulty: The word "DONE!" may already be present in logs from the past. So I anticipate tail -0f may (somehow?) need to be done in the background, instead of grepping in a loop?

Thanks so much,
CG
# 2  
Old 04-11-2013
would it work to have a counter for the string "DONE!" that is initialized to 0 at the start of your script and then enter a loop containing a sleep statement and then after the sleep statement expires count the number of "DONE!" instances to see if it has increased from previous count.

if it has not increased, loop back for another nap (sleep)

if it has increased, run a conditional code path that will increment your DONE counter by 1 and run anything else before it's time to sleep again?

biker
LiveFire Labs: Online UNIX Training with Hands-on Internet Lab
Online UNIX and Linux Training with Hands-on Internet Lab
# 3  
Old 04-11-2013
Can't use a sleep/counter for this solution :(

Good idea, but unfortunately I can't use a sleep/counter anymore Smilie

I am actually currently using a sleep/counter now, but I need to now change it to something that monitors the logs.
...reason being is that the background process that generates this logfile has changed, and the DONE! can happen anywhere from 40 seconds to now 7 minutes.

Although I can technically sleep 7 minutes, because I run this script over and over, it'd be unfortunately way too time consuming if the "DONE!" actually occurs in 50 seconds, for example. -- other things do show in this logfile too, so I can't check for a change in the logfile size either.
# 4  
Old 04-11-2013
What if you just sleep 10 seconds or other short interval, look at the log file, sleep 10 seconds, etc.?
# 5  
Old 04-11-2013
i'm not sure i follow, but i'll probably need to take some time to think about your response in order to ask some relevant follow-up questions. one thing i don't understand is why the script is run "over and over" vs starting it once and letting it run.

in the meantime, have you looked at or considered co-processes/co-routines?

if you're not familiar, here are a few older pages related to the topic...

Co-processes - Part I - Review of Foreground and Background Jobs

Co-processes - Part II - Introduction

Co-processes - Part III - Syntax and Simple Example

biker
# 6  
Old 04-11-2013
I simply suppose you want something like

Code:
tail --retry -f log | while read line
do
grep -q "LOG" 
counter++
done.

or

you may try a simple combination of "tail -f logfile|egrep LOG" and then check the count of output from the command
# 7  
Old 04-11-2013
A better description of what I hope to be doing:

I suppose I should elaborate:

What I'm modifying is a KSH automation script, that's run on demand, for testing a piece of software.

What this KSH script does/need to do: (Step 2)

1) Shutdown, prepare, and restart the software under test (already scripted)

2) Wait for a message (we'll call "DONE!") to appear in /log.txt that says that the MYSQL DB has bound to the RMI/Software.
a. This can take anywhere from 40 seconds to 7+ minutes, depending on DB size..
b. While I can put a 7+ minute delay there, it would be much better if this KSH script continued "as soon as" the "DONE!" message appears in the /log.txt. *This is the challenge.
c. I cannot simply grep the file for "DONE!" in a while loop, because I cannot delete "old/past" logs in this same file that may already contain this word.
d. I also cannot simply check in a while loop for the filesize to change, since other logs are being appended to this same log file during this wait time.

3) Continuing on with already automated tests...


Apologies I wasn't as detailed the first time around!
Thanks so much
CG
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If I ran perl script again,old logs should move with today date and new logs should generate.

Appreciate help for the below issue. Im using below code.....I dont want to attach the logs when I ran the perl twice...I just want to take backup with today date and generate new logs...What I need to do for the below scirpt.............. 1)if logs exist it should move the logs with extention... (1 Reply)
Discussion started by: Sanjeev G
1 Replies

2. Shell Programming and Scripting

Pause before exit

6) printf "\n GoodBye! \n\n"; exit ;; I am trying modify the above command to pause a couple of seconds before exiting, so a message can be displayed. Thank you :). (8 Replies)
Discussion started by: cmccabe
8 Replies

3. Shell Programming and Scripting

Creating a script requiring a pause for user input

Hi I'm trying to create a basic script that pauses for user input to verify a file name before generating the output. I have numerous SSL certificate files which I am trying to determine the expiry date so what I'm trying to do is write a script so that is pauses to request the name of the .pem... (9 Replies)
Discussion started by: Buddyluv
9 Replies

4. Shell Programming and Scripting

Pause shell script till folder doesn't change size anymore

Hi, I recently would like to write a shell script that 1. Runs in the background (can be done with "&", but i'd be happy for other solutions to keep programs running) 2. Does its stuff 3 THEN checks a specified folder for a size change over time (say, each 5 seconds. AND ONLY continues with... (9 Replies)
Discussion started by: pasc
9 Replies

5. Shell Programming and Scripting

script for reading logs of a script running on other UNIX server

Hi, I have a script, running on some outside firwall server and it's log of success or failure is maintained in a file. I want to write a script which ftp that server and reads that file and checks the logs and if failure , I will send mail notification. Please let meknow if I am not... (1 Reply)
Discussion started by: vandana.parwani
1 Replies

6. Shell Programming and Scripting

Pause for remote computing in Telnet script

I am running a telnet script that connects to a database server and executes sql scripts. While the remote database is processing the commands within the sql scripts, my telnet script continues to send commands. Okay, that's fine. They get queued up in the remote server and executed sequentially.... (3 Replies)
Discussion started by: oldjuke
3 Replies

7. Shell Programming and Scripting

KSH script to run other ksh scripts and output it to a file and/or email

Hi I am new to this Scripting process and would like to know How can i write a ksh script that will call other ksh scripts and write the output to a file and/or email. For example ------- Script ABC ------- a.ksh b.ksh c.ksh I need to call all three scripts execute them and... (2 Replies)
Discussion started by: pacifican
2 Replies

8. Shell Programming and Scripting

How to pause a shell script

Hi, I've written a shell script to take photos with my camera. After every picture taken, the picture is transmitted to the computer via usb and then deleted on the camera. But sometimes there's an error and the picture is not deleted and so, after a certain time, the camera chip will be... (4 Replies)
Discussion started by: McLennon
4 Replies

9. Shell Programming and Scripting

Script Pause Until Rsync Is Done Transferring

Alright, I have this script that pulls files from a few locations, process those files, creates a zip file, rsync's it and then removes everything. The problem that I'm having is that I do not know how large the rsync'ed zip file is going to be. Right now I'm using a sleep command before I... (4 Replies)
Discussion started by: droppedonjapan
4 Replies

10. Shell Programming and Scripting

import var and function from ksh script to another ksh script

Ih all, i have multiples ksh scripts for crontab's unix jobs they all have same variables declarations and some similar functions i would have a only single script file to declare my variables, like: var1= "aaa" var2= "bbb" var3= "ccc" ... function ab { ...} function bc { ... }... (2 Replies)
Discussion started by: wolfhurt
2 Replies
Login or Register to Ask a Question