Looping between scripts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Looping between scripts
# 1  
Old 04-04-2005
Looping between scripts

What I need to do is start a loop in one script and end it in another. I cannot figure out how to do this without rewriting the scripts so that the looped code is all in one script (which would be a pain). I am using an AIX box with ksh scripting. Thanks!
# 2  
Old 04-04-2005
Quote:
Originally Posted by driggs96
What I need to do is start a loop in one script and end it in another. I cannot figure out how to do this without rewriting the scripts so that the looped code is all in one script (which would be a pain). I am using an AIX box with ksh scripting. Thanks!
Can't you export a variable that the child process can utilize and continue iterating?
# 3  
Old 04-04-2005
how does the other script break the loop started by the first script? why this requirement?
# 4  
Old 04-04-2005
Basically, the initial script is breaking down an input file into it's logical files. Then it processes the logical files through the remainder of the scripts. The problem that we have encountered is that we need to concatenate the logical files back into one physical file after some of the scripts modifications, but not all of them in order to send proper data back to our customers.
# 5  
Old 04-04-2005
Script 1:
Code:
#! /bin/ksh  
                                                                                        
typeset -x test=0
for i in 1 2 3
do
    print "s1.sh: $test"
    (( test += 1))
done

./script2.sh

Script 2:
Code:
#! /bin/ksh  
while [ $test -lt 10 ]
do
    print "t2.sh: $test"
    (( test += 1 ))
done

Output:
Code:
script1.sh: 0
script1.sh: 1
script1.sh: 2
script2.sh: 3
script2.sh: 4
script2.sh: 5
script2.sh: 6
script2.sh: 7
script2.sh: 8
script2.sh: 9

# 6  
Old 04-04-2005
Quote:
Originally Posted by driggs96
Basically, the initial script is breaking down an input file into it's logical files. Then it processes the logical files through the remainder of the scripts. The problem that we have encountered is that we need to concatenate the logical files back into one physical file after some of the scripts modifications, but not all of them in order to send proper data back to our customers.
for what you need to do --- in my opinion anyways --- you'd be better off putting all the code to breakdown and reconfigure the input file into functions in the big script for easier control ... (see pseudo-code) ...
Code:
process_file(){
    create small_files
    for file in small_file*
    do
        /ext/script $file
    done
}

put_back_file(){
    for file in small_file*
    do
         if [ cond ]
         then
                cat $file >> new_big_file
         fi
    done
}

do_the_work(){
    process_file
     while [ ! -f small_file* ]
    do
          sleep 5
    done
    put_back_files
}

do_the_work
if [ -f new_big_file ]
then
    mailx -s "whatever" client.email < new_big_file
else
    echo "can't see new_big_file"
fi

you might want to make sure you count the small_file* before creating new_big_file ...
Code:
check_file_count(){
    filecount=10
    if [ -f small_file* ]
    then
           mycount=`ls small_file* | wc -l`
           while [ $mycount -lt  $filecount ]
           do
                sleep 5
                mycount=`ls small_file* | wc -l`
           done
    else
          sleep 5
          check_file_count
     fi
}

do_the_work(){
    process_file
    check_file_count
    put_back_files
}

do_the_work
if [ -f new_big_file ]
then
    mailx -s "whatever" client.email < new_big_file
else
    echo "can't see new_big_file"
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Calling multiple scripts from another scripts

Dear all, I am working on script which call other shell scripts in a loop but problem is from second script am not able to come out. Here is the snippet:- #!/bin/bash HSFILE=/root/Test/Components.txt LOGFile=/opt/domain/AdminDomain/application/logs... (3 Replies)
Discussion started by: sharsour
3 Replies

2. Shell Programming and Scripting

KSH - How to call different scripts from master scripts based on a column in an Oracle table

Dear Members, I have a table REQUESTS in Oracle which has an attribute REQUEST_ACTION. The entries in REQUEST_ACTION are like, ME, MD, ND, NE etc. I would like to create a script which will will call other scripts based on the request action. Can we directly read from the REQUEST_ACTION... (2 Replies)
Discussion started by: Yoodit
2 Replies

3. Shell Programming and Scripting

Changing the Bash Scripts to Bourne Scripts:URGENT

Hi, I have to write a program to compute the checksums of files ./script.sh I wrote the program using bash and it took me forever since I am a beginner but it works very well. I'm getting so close to the deadline and I realised today that actually I have to use normal Bourne shell... (3 Replies)
Discussion started by: pgarg1989
3 Replies

4. Shell Programming and Scripting

Running scripts within scripts from cron

Hi all, I have set up a cron job which calls another shell script shell script which in turn calls a Java process. The cron tab looks so. 0,30 7-18 * * 1-5 /u01/home/weblogic/brp/bin/checkstatus.sh >> /u01/home/weblogic/logs/checkstatus.log The checkstatus.sh scripts looks like this. ... (4 Replies)
Discussion started by: sirbrian
4 Replies

5. Shell Programming and Scripting

Help with Script using rsh and scripts within scripts

Hi, I've written a script that runs on a Database server. It has to shutdown the Application server, do an Oracle Dump and then restart the Application server. Its been a long time since I wrote any shells scripts. Can you tell me if the scripts that I execute within my script will be executed... (3 Replies)
Discussion started by: brockwile1
3 Replies

6. UNIX for Dummies Questions & Answers

Profile scripts versus rc scripts....

what is the difference between login and profile scripts versus the rc scripts? (1 Reply)
Discussion started by: rookie22
1 Replies

7. Shell Programming and Scripting

help with looping

vesselNames values: xxx yyy zzz vesselPlanned values: xxx zzz zzz zzz OIFS="" OIFS=$IFS IFS="\n" (2 Replies)
Discussion started by: finalight
2 Replies

8. Shell Programming and Scripting

help on looping using if/for or while

Hello, where can I get usefull information on the use of looping with for , if and while with extensive examples. Also use of variables in scripts (1 Reply)
Discussion started by: sam4now
1 Replies

9. Shell Programming and Scripting

for looping

I run into a issue when I try to do sorting of the following with ascending order, one round of for looping seems not working, anyone knows how to use shell or perl? $array = (5,0,3,2,7,9,8) (2 Replies)
Discussion started by: ccp
2 Replies

10. UNIX for Dummies Questions & Answers

Help with looping

Hi, Actually I have a file which consists data . for eg names. Then I want my sql query to read this file and produce the output. Currently I am using this FOR EG : FILENAME is NAMES for i in `cat NAMES` { sqlplus -s $CONNECTID << EOF spool rooh set heading off select... (1 Reply)
Discussion started by: rooh
1 Replies
Login or Register to Ask a Question