Sponsored Content
Top Forums Shell Programming and Scripting Breaking Loop by using another script Post 302338460 by anushree.a on Tuesday 28th of July 2009 03:10:41 AM
Old 07-28-2009
Breaking Loop by using another script

Hi friends,
I have 2 scripts. 1) Master_Script.sh and 2) Sub_script.sh
We run Master_script.sh manually where as sub_script.sh keeps generating output in every 2 minutes (through crontab). The output generated by sub_script.sh can be 0 or 1.

As I told you, sub-script.sh keeps generating o/p in every 2 minutes, as soon as output of sub_script.sh ($sub_script_o/p) is 0 then somehow Master_script.sh should jump directly to "done" leving whatever it is doing in "for" loop.



# Master_script.sh
aa
bb
cc
dd
ee
for
ff
gg
hh
sh ii.sh #while this script is running if $sub_script_o/p is 1 then let ii.sh run but if $sub_script_o/p is 0 then directly jump to "done" so that loop will break and next item in loop will be executed.
jj
kk
done




# sub-script.sh
a
b
c
d
e
f
#it will generate output either 0 or 1 in variable $sub_script_o/p

Situation is such that Master_script.sh runs sh ii.sh in "for loop" as mentioned in my question. ii.sh gets terminated because of some error (Output of sub_script.sh i.e. $sub_script indicates whether ii.sh is running or not. 1=running, 0=terminated) and hence the loop gets stuck in between.

To solve this problem I am planning to write sub_script.sh which will make Master_script.sh to go to next iteration when ii.sh is stuck in between. This will help me keep running the Master_script.sh even if it faces some problem with a particular iteration.


Please advice.
Thank you for taking interest
Anushree

Last edited by anushree.a; 07-30-2009 at 03:19 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

rsh breaking me out of loop

Hey all I have two scripts, one script containing the guts of my code. The other simply loops through a list, calling the other script on each iteration. Problem is when I add the line `/usr/bin/rsh -l root $HOSTNAME ""` to my main script, the loop never seems to exectute any more... (1 Reply)
Discussion started by: mark007
1 Replies

2. Linux

breaking out of while loop

Hi , I am running this script ( pasting only error code ) to generate some ddl definition for tables . But what I want is to break out of the db2look part when the base_table is not like DIM_$TN or FACT_$TN . After this it should come back to while loop to read the next TN . I read the other... (3 Replies)
Discussion started by: capri_drm
3 Replies

3. Shell Programming and Scripting

Breaking if-else loop and variety of comparisions

Hello Friends, Im trying to write a script to invoke nagios. In order to do this I grep some words that comes from output of some backup scripts. When there is "End-of-tape detected" in directed output logs it should give alarm. First I would like to know if there is any better way to write... (5 Replies)
Discussion started by: EAGL€
5 Replies

4. SCO

Restrict user from breaking out of login script

I have a login script similar to where the user's shell in /etc/passwd is set to csh: echo "In .login" setenv SHELL /bin/csh /bin/sh -c trap "" 1 2 3 5 6 7 8 15 /path/to/application logout --------------------- however, even with the trap command the user is still able to... (1 Reply)
Discussion started by: kuliksco
1 Replies

5. Shell Programming and Scripting

Stop a program without breaking the script?

Hello there! I am creating a script, that among other functions will run iperf (network stress tool) either on server or client mode. The thing is that it will run forever if the user does not stop it or break it. CTRL-C will break it. I need a method, however, that will break iperf and then... (2 Replies)
Discussion started by: ppucci
2 Replies

6. Shell Programming and Scripting

How to loop use while loop in csh script?

Hi all, i got 2 text file. file.txt value.txt i want use C shell script to write out while both of the file got different limit....how i going to write it in 1 while loop? (4 Replies)
Discussion started by: proghack
4 Replies

7. Shell Programming and Scripting

Breaking out of loop

I have a main script with while loop having for loop inside. Again in for loop based on if condition few functions will be called. So when a function is called for certain condition it should come out from the main for loop and should continue with while loop. Let me explain with example here: I... (6 Replies)
Discussion started by: vpv0002
6 Replies

8. Shell Programming and Scripting

breaking for loop

Dear Friends, Here I need your guidance once again. I have for loop which check all files in a folder for a particular string. If the string is found in a file it returns value other than 0 else returns 0 value in variable t2. At times the string which we are looking for is in first file... (1 Reply)
Discussion started by: anushree.a
1 Replies

9. Shell Programming and Scripting

Ssh to remote server loop is breaking

hi All, cat login.list server1 userid1 server2 userid2 server3 userid3 ---------------------------------------- #SSHSCRIPT.ksh FILE=login.list while read vah vah_id do ssh $vah -l $vah_id "pwd" done < "$FILE" ----------------------------------------- When i... (2 Replies)
Discussion started by: raghur77
2 Replies

10. Shell Programming and Scripting

While loop breaking when using "ssh" command inside

Hi , I am trying to read a list of hosts from a config file and trying to get file list from that host. For this I have used one while loop. cat "$ARCHIVE_CFG_FILE" | sed '/^$/d' | sed '/^#/d' | while read ARCHIVE_CFG do SOURCE_SERVER_NAME=`echo "$ARCHIVE_CFG" | awk -F '|' '{ print... (2 Replies)
Discussion started by: Anupam_Halder
2 Replies
exit(1)                                                            User Commands                                                           exit(1)

NAME
exit, return, goto - shell built-in functions to enable the execution of the shell to advance beyond its sequence of steps SYNOPSIS
sh exit [n] return [n] csh exit [ ( expr )] goto label ksh *exit [n] *return [n] DESCRIPTION
sh exit will cause the calling shell or shell script to exit with the exit status specified by n. If n is omitted the exit status is that of the last command executed (an EOF will also cause the shell to exit.) return causes a function to exit with the return value specified by n. If n is omitted, the return status is that of the last command exe- cuted. csh exit will cause the calling shell or shell script to exit, either with the value of the status variable or with the value specified by the expression expr. The goto built-in uses a specified label as a search string amongst commands. The shell rewinds its input as much as possible and searches for a line of the form label: possibly preceded by space or tab characters. Execution continues after the indicated line. It is an error to jump to a label that occurs between a while or for built-in command and its corresponding end. ksh exit will cause the calling shell or shell script to exit with the exit status specified by n. The value will be the least significant 8 bits of the specified status. If n is omitted then the exit status is that of the last command executed. When exit occurs when executing a trap, the last command refers to the command that executed before the trap was invoked. An end-of-file will also cause the shell to exit except for a shell which has the ignoreeof option (See set below) turned on. return causes a shell function or '.' script to return to the invoking script with the return status specified by n. The value will be the least significant 8 bits of the specified status. If n is omitted then the return status is that of the last command executed. If return is invoked while not in a function or a '.' script, then it is the same as an exit. On this man page, ksh(1) commands that are preceded by one or two * (asterisks) are treated specially in the following ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. Words, following a command preceded by ** that are in the format of a variable assignment, are expanded with the same rules as a vari- able assignment. This means that tilde substitution is performed after the = sign and word splitting and file name generation are not performed. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
break(1), csh(1), ksh(1), sh(1), attributes(5) SunOS 5.10 15 Apr 1994 exit(1)
All times are GMT -4. The time now is 06:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy