trying to grep the first few lines of a continuos script, and exit the script anyidea


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers trying to grep the first few lines of a continuos script, and exit the script anyidea
# 1  
Old 07-22-2009
trying to grep the first few lines of a continuos script, and exit the script anyidea

Hi.

I am trying to extract the output of the first few lines of a continuos sh script.

The when i run it, i wont to grep the the first 20 lines of it for an entry and basically do a crtl z out of it or to that effect, and output the results to a text file.

I basically want to script the above. so when i run the script it will call the script which, grep the first 20 lines outputted and exit this continuos script.

Would anyone have an idea what would be the easiest way in doing this.

At the moment i am able to grep the first 20 lines look for the entry, However the script is continusaally running need to exit it
# 2  
Old 07-22-2009
Grep is a search utility. Obviously, you can use it to return results from a file to text, and I use it for this from time to time. However, I believe you can go at this in a different way, that will be a solution to your issue. I would do the following:

Code:
tail -n 20 >> output.txt

This will output the last 20 lines that are currently written to the continuously written log file, and outputs the data to a text file. The example above appends to the file (does not overwrite). If you want it to overwrite:

Code:
tail -n 20 > output.txt

Let me know if you have any questions.
# 3  
Old 07-22-2009
Hi drewrockshard.

What i am trying to do is.

I have to run a script x ( Which loops for ever)

I need to grep a particular line from the output of the script x, Which i expect to be outputted within the first 20 lines, However this scripts stays running forever till i do a ctrl z.

So i am trying to create a script y which will execute script x grep for the expected output and ctrl d from script x. and output the findings from executing script x.

Script y
==============================

Calls script x looks for a pattern and ctrl z from script x.

i need to be able to force exit the script x when i find the pattern

as script x runs continuous


==================================
# 4  
Old 07-22-2009
Quote:
Originally Posted by k00061804
Hi drewrockshard.

What i am trying to do is.

I have to run a script x ( Which loops for ever)

I need to grep a particular line from the output of the script x, Which i expect to be outputted within the first 20 lines, However this scripts stays running forever till i do a ctrl z.

So i am trying to create a script y which will execute script x grep for the expected output and ctrl d from script x. and output the findings from executing script x.

Script y
==============================

Calls script x looks for a pattern and ctrl z from script x.

i need to be able to force exit the script x when i find the pattern

as script x runs continuous


==================================
First of all, I apologize for the lack of "attention to detail". You stated the first 20 lines, not the last 20 lines. In this case, just to correct myself, it would be:

Code:
head -n 20 >> output.txt

or

Code:
head -n 20 > output.txt

Now, on with what you are actually wanting. I find your logic a bit confusing. What I would do, in this case it to take script x and code it to log everything that you need to a log file. I would then have script y run, and run script x, just like you were wanting. After it starts script x, make sure you get the PID of the process and load it into a variable. Then have script y grep the log file of script x and when if finds a match for what you are looking for, have script y kill the pid of script x.
# 5  
Old 07-22-2009
Hi drewrockshard.

Your logic describes exactly what i should do to get the desired output.

It looks like when i find the pattern i am looking for in the log file. i should kill the process id of script x as you say,it seems to be the correct way to do this.

The way i was trying to do it was not to log the output of script x to a log, but run the script, wait till i get the pattern i was looking for and kill off the script someway. But you logic seems better

Thanks for the help
# 6  
Old 07-22-2009
No problem man. Let me know if you need any help with the scripting part! Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Need to grep two lines from the topas command through a Korn Script

I need to grep two lines from topas command in one of my AIX server. Topas Monitor for host: semas001 EVENTS/QUEUES FILE/TTY Wed Jan 29 10:12:06 2014 Interval: 2 Cswitch 764 Readch 4473.1K Syscall 5166 ... (4 Replies)
Discussion started by: rpm120
4 Replies

2. Shell Programming and Scripting

How to capture the exit code of a shell script in a perl script.?

hi, i want to pop up an alert box using perl script. my requirement is. i am using a html page which calls a perl script. this perl script calls a shell script.. after the shell script ends its execution, i am using exit 0 to terminate the shell script successfully and exit 1 to terminate the... (3 Replies)
Discussion started by: Little
3 Replies

3. Shell Programming and Scripting

How to capture exit code of child script and send it to parent script?

#!/usr/local/bin/bash set -vx /prod/HotelierLinks/palaceLink/bin/PalacefilesWait /prod/HotelierLinks/palaceLink/bin/prodEnvSetup 03212013 & if then echo "fatal error: Palace/HardRock failed!!!!" 1>&2 echo "Palace Failed" | mail -s "Link Failed at Palace/HardRock" -c... (1 Reply)
Discussion started by: aroragaurav.84
1 Replies

4. Shell Programming and Scripting

How to get the exit status of a command in nner script to the outer script?

Hi all, I have a shell script inside which i am executing another shell script. In the inner script im executing a command. i want the status of that command in the outer script to perform some validations. How to get its status please help!!1 Im using ksh. (2 Replies)
Discussion started by: Jayaraman
2 Replies

5. Shell Programming and Scripting

shell script: grep multiple lines after pattern match

I have sql file containing lot of queries on different database table. I have to filter specific table queries. Let say i need all queries of test1,test2,test3 along with four lines above it and sql queries can be multi lines or in single line. Input file contains. set INSERT_ID=1; set... (1 Reply)
Discussion started by: mirfan
1 Replies

6. Shell Programming and Scripting

How to grep sql error in shell script and exit the script?

I need help in the following script. I want to grep the sql errors insert into the error table and exit the shell script if there is any error, otherwise keep running the scripts. Here is my script #!/bin/csh -f source .orapass set user = $USER set pass = $PASS cd /opt/data/scripts echo... (2 Replies)
Discussion started by: allinshell99
2 Replies

7. UNIX for Dummies Questions & Answers

exit a script

Hi Guys, I have a script which takes reply from user and executes the corresponding scirpt. Below is the script PS3 = 'Enter the options of your choice(x to exit)=>' select useropt in 'List Processess' \ 'List semaphores' do case $REPLY in 1) abc.sh ... (13 Replies)
Discussion started by: vandi
13 Replies

8. UNIX for Dummies Questions & Answers

Exit out of the Script Command inside a Script

I'm new to Linux. I have a bash script that invokes an executable. I'd like use the SCRIPT command inside the script and exit out of the script command after it writes to the file. Does this make sense? Below is an example of the contents of my script. #BEGIN SCRIPT script typescript... (6 Replies)
Discussion started by: jmungai
6 Replies

9. Shell Programming and Scripting

[Help] PERL Script - grep multiple lines

Hi Gurus, I need some help with the "grep" command or whatever command that you think suitable for me. I'm about to write a perl script to extract a report from the system and submit it to the end users. The input for the script will consist of 3 element. 1) Generation ID 2) Month 3) Year... (6 Replies)
Discussion started by: miskin
6 Replies

10. Shell Programming and Scripting

exit from script

I have a shell script with options, one of which should exit the system (logout), however when I select this option it drops down to shell, is there a command other than exit that will close the session completely ? (1 Reply)
Discussion started by: gefa
1 Replies
Login or Register to Ask a Question