Complex loop...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Complex loop...
# 1  
Old 12-12-2005
Complex loop...

Hi,

I did a lot of search for this but I could not find it, so I am posting it here....Please help.

I have a situation where I need to do polling or sleep for a while...here is what I have..

#! /usr/bin/sh
job1 runs > result1.txt
RESULT1_CNT=`wc -l result1.txt | awk '{ print $1 }'`
if[ RESULT1_CNT -gt 0 ]
then
while [ RESULT1_CNT -gt 0 ]
do
JOb2 runs
RESULT1_CNT=RESULT1_CNT-1
done
else
#This is the part I am struggling for....
#here it should sleep for specified time and run job1 again...
#if the RESULT1_CNT is not greater than 0 three consecutive times
#then it should exit

any help is appreciated...

Thanks,

Girinath.
# 2  
Old 12-12-2005
This is a start:
Code:
#! /usr/bin/ksh

let consecutive=-1
while true
do
    job1 runs > result1.txt
    RESULT1_CNT=`wc -l result1.txt | awk '{ print $1 }'`
    if [ $RESULT1_CNT -lt 1 ]; then
        let consecutive=$consecutive+1
        if [ $consecutive -eq 2]; then  # note: -1 + 3 = 2
             exit 1                  
        fi 
    else
        let consecutive=-1
    fi
    if[ $RESULT1_CNT -gt 0 ]; then
        while [ RESULT1_CNT -gt 0 ]
        do
           JOB2 runs
           RESULT1_CNT=RESULT1_CNT-1
        done
    fi
    sleep 60
done

Note that I used ksh...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Complex if then else

for i in $(condition ONE);do for e in $(CONDITION TWO);do if ; then command 1 command 2 command 3 else if ; then command 1 command 2 command 3 else if ; then ... (6 Replies)
Discussion started by: elilmal
6 Replies

2. Shell Programming and Scripting

Help with Complex Awk.

Hi, I have a file. In this file when ever the word "ABC" occurs at position from 25 and 34 I would like to replace the value at postion 100 to 5 for the first 1000 rows only. I have written the following Awk command. nawk 'substr($0,25,9)=="ABC" {print $0}' filename The above command... (4 Replies)
Discussion started by: pinnacle
4 Replies

3. Shell Programming and Scripting

Get values from 2 files - Complex "for loop and if" awk problem

Hi everyone, I've been thinking and trying/changing all day long the below code, maybe some awk expert could help me to fix the for loop I've thought, I think I'm very close to the correct output. file1 is: <boxes content="Grapes and Apples"> <box No.="Box MT. 53"> <quantity... (8 Replies)
Discussion started by: Ophiuchus
8 Replies

4. Shell Programming and Scripting

complex requirement

i have a requirement to search a pattern1 and once the pattern1 is found i have to go up and search pattern2 and if pattern2 is found i have to search down for pattern3 and pattern4. once this cycle is compelted, again i have to search pattern1 and pattern2,3,4 i am able to do this by opening... (9 Replies)
Discussion started by: tnvanathy23
9 Replies

5. Shell Programming and Scripting

Complex Compare

Hi All, File1.txt File2.txt Above are the two input file's: Always I use to get three rows for File1.txt File1.txt (fixed width) 2nd line i will get date and 3rd record i will get a number. File2.txt (Pile delimeter) will contains 'n' number of records were header & footer is... (4 Replies)
Discussion started by: kmsekhar
4 Replies

6. Shell Programming and Scripting

Complex query

A file whose location i am not aware of contains the below text <url>jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(FAILOVER=on)(ADDRESS=(PROTOCOL=TCP) (HOST=ngm2sn1p2-vip.mybank.net)(PORT=4001))(ADDRESS=(PROTOCOL=TCP)(HOST=ngm2sn2p2-vip.mybank.net)... (1 Reply)
Discussion started by: mohtashims
1 Replies

7. Shell Programming and Scripting

Complex Script

hey... i had a big problem with my professor i have 3 simple archives in.txt -> had all timestamps of users logon (100lines) ex. 111111 222222 333333 out.txt -> had all timestamps of users logof (100lines) ex. 111113 222225 333332 commands.txt... (9 Replies)
Discussion started by: beandj
9 Replies

8. UNIX for Dummies Questions & Answers

Complex Commands

I need to ideas for some complex commands for a script file. Any ideas would be greatly appricated (2 Replies)
Discussion started by: trob
2 Replies

9. Solaris

how to complex.h in C on SUN

Hi, The C code we've written work ok on Mac, but make a " segmentation fault" when running on SUN. One potential bug is complex.h because the complex.h in the lib/ is licensed by Apple. Does anybody know how to add in complex.h into lib/ on the SUN so we can deal with complex numbers in our code?... (3 Replies)
Discussion started by: xtong
3 Replies

10. Shell Programming and Scripting

Complex use with awk

Hi , I have file named docs.txt The content of the file look like this: DOC disk location Size ======= ===== ============= ========= TXT A /dev/dm-1 10 TXT B /dev/dm-2 10 BIN C ... (3 Replies)
Discussion started by: yoavbe
3 Replies
Login or Register to Ask a Question