bash script tail when string found do something


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bash script tail when string found do something
# 1  
Old 08-06-2009
bash script tail when string found do something

Okay, I have two scripts, the first one does some stuff, and comes to a point where it has this:

Right here it runs a quick script to start something that writes to a log file.
Code:
/usr/bin/tail -f ${pathVar}/nohup_${servVar}.out |
while read -r line
do
   [[ "$line" != *Server\ state\ changed\ to\ RUNNING* ]] && continue
        cd ${pathVar}
        ./markerReset
exit
done
exit

This calls another script that does basically the same thing:

Before this line it calls a script that starts something that prints to a log.
Code:
cd ${MSD}
/usr/bin/tail -f ${MSD}/nohup_${servVar}.out |
while read -r line
do
   [[ "$line" != *Server\ state\ changed\ to\ RUNNING* ]] && continue
        echo "Marker Reset Complete"
done
exit

My logic may be way off here, but what I need is the following:

The first script shuts down the two servers, then it cd's to a directory, deletes some directories and then re-creates them, then it starts the first server. Once that server prints the line in the first CODE box, it should run the second script, which runs another script that starts a different server. once the line in the second CODE box is printed, it should echo Marker Reset Complete, and then exit the script it's in, as well as then exit the first script.

Right now, it seems to run perfect until the end, then at the end it prints the marker reset complete line, but then it doesn't do anything for 20-30 seconds until it FINALLY exit's.

---------- Post updated at 02:05 PM ---------- Previous update was at 10:46 AM ----------

I'm sure this isn't the most efficient way to accomplish what I'm trying to do, but has anyone seen this issue before when after tailing a file and reading it for a line you get a long delay after the line is found and the script is supposed to go on tot he next step?

---------- Post updated 08-06-09 at 09:06 AM ---------- Previous update was 08-05-09 at 02:05 PM ----------

someone out there has to have an idea on this.

---------- Post updated at 02:50 PM ---------- Previous update was at 09:06 AM ----------

Here is my solution, not exactly the way I originally wanted it, but this runs much quicker and more efficiently.

Code:
testVar=0
counter=0
while [ $testVar -eq "0" ]
do
sleep 3
counter=$(( $counter + 1 ))
        if grep -q 'RUNNING' ${MSD}/nohup_${SERVER_NAME}.out
                then
                        echo "Reset Complete"
                        testVar="1"
        fi
        if [[ -n "${counter}" && ${counter} -gt 80 ]]
        then
                echo "Marker Reset timed out"
                exit
        fi
done
exit

used a similar version of that in both scripts.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash to search file for string and lauch function if found

In the bash below I am searching the filevirus-scan.log for the Infected files: 0 line (in bold) and each line for OK. If both of these are true then the function execute is automatically called and processing starts. If both these conditions are not meet then the line in the file is sent to the... (2 Replies)
Discussion started by: cmccabe
2 Replies

2. UNIX for Dummies Questions & Answers

Execute shell script and if string found while executing then exit

Hi All, I have one shell script start.sh which executes another shell script test.sh something like below :test.sh -param1 -param2 In the test.sh there is one command for removing file:rm file1.bak I want whenever I execute start.sh, it will execute test.sh and if it finds string rm... (7 Replies)
Discussion started by: ORAI
7 Replies

3. UNIX for Dummies Questions & Answers

File Not found - Bash script

I'm facing issues in executing the bash script of mine. This script will pick the latest file received and connects SFTP server and files is placed on this remote server. Error message Enter password: "File movement" sftp> cd Test sftp> put Test_File_201309.txt File "Test_File_201309.txt"... (6 Replies)
Discussion started by: parpaa
6 Replies

4. UNIX for Dummies Questions & Answers

Im new to bash scriping and i found this expression on a bash script what does this mean.

# check host value regex='^(||1|2|25)(\.(||1|2|25)){3}$' if ')" != "" ]; then if ]; then echo host $host not found exit 4 fi elif ]; then echo $host is an invalid host address exit 5 fi espeacailly the top regex part? ---------- Post updated at 06:58 PM ---------- Previous update was... (1 Reply)
Discussion started by: kevin298
1 Replies

5. Shell Programming and Scripting

bash: need to have egrep to return a text string if the search pattern has NOT been found

Hello all, after spending hours of searching the web I decided to create an account here. This is my first post and I hope one of the experts can help. I need to resolve a grep / sed / xargs / awk problem. My input file is just like this: ----------------------------------... (6 Replies)
Discussion started by: bash4ever
6 Replies

6. Shell Programming and Scripting

bash script search file and insert character when match found

Hi I need a bash script that can search through a text file and when it finds 'FSS1206' I need to put a Letter F 100 spaces after the second instance of FSS1206 The format is the same throughout the file I need to repeat this on every time it finds the second 'FSS1206' in the file I have... (0 Replies)
Discussion started by: firefox2k2
0 Replies

7. UNIX for Dummies Questions & Answers

Launch shell script if string match is found

I'm trying to write a simple shell script that looks at a given text file and if the only word in the file is 'completed', it launches another shell script. So far I have this almost working... if grep 'completed' $datafile then... however, using this logic the secondary shell script... (3 Replies)
Discussion started by: MickeyGreen
3 Replies

8. Shell Programming and Scripting

bash script to display tail

Hi everyone, I'm trying to write a script to format a file using unix2dos. I want to output all but the first 14 lines in a file. Then I want to pipe this to unix2dos to convert the output to a file that's easily readable on windows. Here's what I have: export Lines=`wc -l < $1` export... (11 Replies)
Discussion started by: LuminalZero
11 Replies

9. Shell Programming and Scripting

rm:command not found in linux Bash shell script

Hi All, Linux lxs3er06 2.6.9-67.ELsmp #1 SMP Wed Nov 7 13:58:04 EST 2007 i686 i686 i386 GNU/Linux Issue: While executing shell scripts in bash shell, following error messages are thrown: rm:command not found On doing little investigation, I added '/bin' to $PATH and on doing echo... (9 Replies)
Discussion started by: a1_win
9 Replies

10. Shell Programming and Scripting

Stopping tail -f when certain string found?

Hi, I need to monitor a log file for a certain string ("Phase 2 ended") which indicates that the job which creates the log file has finished loading its data file. Once the string "Phase 2 ended" is found in the log file I would then like to stop checking that log and check to see if another... (3 Replies)
Discussion started by: jake657
3 Replies
Login or Register to Ask a Question