Problem in making itration


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem in making itration
# 1  
Old 06-23-2009
Question Problem in making itration

Hi,

I have a file which keeps on appending the data continuously, i that i am looking for a particular pattern, if i dont find that pattern i want to wait for 30 seconds to check it again.

can we use it like this
-----------------------------
until [ $? -eq "0" ]
do

cat $line | tail -5 | grep 'PATTERN' > /dev/null

sleep 30
done

echo "File Contains the pattern 'PATTERN' now"
------------------------------------------------------
i am not able to get it, even if pattern is not there it is coming out of loop and executing echo command in any case.

Can someone plesae help me on this

thanks in advanceSmilie
# 2  
Old 06-23-2009
First off, you should post ALL of the code, not just a snippet of the until loop. Based on your post, I have no clue what "$line" is.

Second, please use the code box/tags for your code...thats the little "#" icon near the top right of the toolbar when you are making a post.

Third, the reason that your loop is exiting is that "$?" was 0 when you started the loop. Its kinda like saying this:

Code:
until [ 1 -eq 1 ]; do
    ./stuff
done

the command ./stuff will never run.and even if "$?" was not 0 to start off the loop, the "sleep 30" command would certainly have a 0 exit status.

So, what you probably want to do is something like this:

Code:
until cat $line | tail -5 | grep 'PATTERN' > /dev/null 2&>1; do
    sleep 30
done

echo pattern PATTERN found

You do not really have to do a test/comparison (i.e. [ 1 -eq 1 ]) with a while, or until loop, as it just evaluates the exit status of the command after "until". Believe it or not, the square bracket comparison is actually a command (its the "test" command).

Last edited by Gee-Money; 06-23-2009 at 10:05 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem in making a list with awk

Hi bodies,I am doing a list from a .txt file with awk commands but something is wrong. The .txt file looks like: 32782 28 18 32783 02 18 32784 01 18 32785 29 18 32786 25 23 32787 25 18 32788 00 18 32789 25 26 32790 02 23 32791 29 26 ... (2 Replies)
Discussion started by: Behrouzx77
2 Replies

2. Shell Programming and Scripting

problem in making Awk executable script

Guys I placed #!path/awk -f placed awk script and used $1 to call 1st inputfile inside the script. But some where I did mistake. Could you please help me run this script as executable I forgot to mention I also used BEGIN before placing awk script. But nothing worked out. Script ... (2 Replies)
Discussion started by: repinementer
2 Replies

3. Shell Programming and Scripting

[problem] making a backup files

Hi guys, I'm a little stuck on this problem, I've tried googling it and some trial and error but can't seem to get it working. Basically I need the script to: 1) create a directory called "mybackups", if it doesn't exist 2) go through all the .sh files in the current directory, and copy... (4 Replies)
Discussion started by: chazij
4 Replies

4. Shell Programming and Scripting

problem in making sftp script

Dear all I am bit new to shell scripting . I am implemented autossh between two sun solaris machines , so that when I use sftp it will not ask for the password. Now I need to make shell script in which I have to transfer files from one server to another server automatically through root... (8 Replies)
Discussion started by: girish.batra
8 Replies

5. UNIX for Dummies Questions & Answers

problem while making ftp of a large file

Hi Friends, I'mfacing a problem while doing ftp of a large file.The control session is getting closed after sometime.But data session transfers the file successfully even when the control seeion is lost.I need to make the control session available as long as data session is active. How can i... (1 Reply)
Discussion started by: rprajendran
1 Replies

6. UNIX for Advanced & Expert Users

problem in making autossh between windows and solaris

Dear all I am facing one problem which is related to enabling Autossh between windows and solaris machine. If suppose their are two servers, server A is having windows and server B is having Solaris.I install openssh server software for windows through sourceforge.net site. What my requirement... (7 Replies)
Discussion started by: girish.batra
7 Replies

7. Shell Programming and Scripting

problem in making file name from date command

Dear all I am bit new to programming. I have to redirect the output to a file which will be in the following format man ls> date +"hup-%m%d%y-%H%M" --------> this will show me the month,day,year,hours and minute in a file name whose name start from "hup-" kindly any correct my syntax (2 Replies)
Discussion started by: girish.batra
2 Replies

8. Shell Programming and Scripting

Problem in making shell script

Dear all Dear Brother I am bit new to programming or shell scripting. I have given one shell script which is regarding combining all the 240 or less files in a particular folderwhich is related to one hour of the day. There will be 24 these kind of folders related to a day . It means there... (4 Replies)
Discussion started by: girish.batra
4 Replies

9. Programming

DDD making problem

Hi Everybody, I am trying to make the ddd-3.3.9 debugger. I installed all dependencies. this is what i get: # make Making all in themes make: Entering directory `/space/atoulan/ddd-3.3.9/themes' make: Nothing to be done for `all'. make: Leaving directory... (0 Replies)
Discussion started by: azazel11998
0 Replies
Login or Register to Ask a Question