Sponsored Content
Top Forums Shell Programming and Scripting Breaking "while read" also breaks the parent process Post 302437748 by pludi on Friday 16th of July 2010 04:37:25 AM
Old 07-16-2010
The reason your program is breaking is that the break will exit the loop, ending the read, which sends a SIGPIPE to myprogram, which usually is an exit condition.

Do you have influence on the code of the program being started? If so, have it create a file once it's done, for which you can wait.

If not you'll have to put the reading loop into the background, and have it signal the main program once it's done. Something like
Code:
#!/bin/sh

waiting=1
ppid=$$

trap waiting=0 USR1

(
  ./myprogram | while read -r
  do
    [[ "$REPLY" == "up and running" ]] && kill -USR1 $ppid
  done
) &

printf "Waiting for startup"
while [ $waiting -eq 1 ]
do
  printf '.'
  sleep 1
done
echo

: # Stuff to be done here

wait #Wait for "myprogram" to exit

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to request a "read" or "delivered" receipt for mails

Dears, I've written a script which allows me to send mails in different formats with different attaches. Now I still want to add a feature to this script. My users would like to be able to receive a "read" or "delivered" receipt for their mails. The script send mails on behalve of an specific... (1 Reply)
Discussion started by: plelie2
1 Replies

2. Shell Programming and Scripting

Breaking input with "read" command

In this post, Perderabo's script says echo 05/06/25 14:15:56 | IFS=" /:" read Y1 M1 D1 h1 m1 s1 which, if I am not wrong, will break the input into Y1, M1 et al. I tried the following in my code #! /bin/ksh # per.sh typeset -R2 HOUR=00 typeset -R2 MIN=00 typeset -R2 SEC=00 ... (2 Replies)
Discussion started by: vino
2 Replies

3. Shell Programming and Scripting

read -p "prompt text" foo say "read: bad option(s)" in Bourne-Shell

Hallo, i need a Prompting read in my script: read -p "Enter your command: " command But i always get this Error: -p: is not an identifier When I run these in c-shell i get this error /usr/bin/read: read: bad option(s) How can I use a Prompt in the read command? (9 Replies)
Discussion started by: wiseguy
9 Replies

4. Red Hat

"service" , "process" and " daemon" ?

Friends , Anybody plz tell me what is the basic difference between "service" , "process" and " daemon" ? Waiting for kind reply .. .. (1 Reply)
Discussion started by: shipon_97
1 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Shell Programming and Scripting

Purpose of "read" and "$END$" in ksh ?

Hi, Could anyone please shed some light on the following script lines and what is it doing as it was written by an ex-administrator? cat $AMS/version|read a b verno d DBVer=$(/usr/bin/printf "%7s" $verno) I checked that the cat $AMS/version command returns following output: ... (10 Replies)
Discussion started by: dbadmin100
10 Replies

7. Shell Programming and Scripting

Read from "list1" and list matches in "list2"

I want to print any matching IP addresse in List1 with List 2; List 1 List of IP addresses; 161.85.58.210 250.57.15.129 217.23.162.249 74.76.129.101 30.221.177.237 3.147.200.59 170.58.142.64 127.65.109.33 150.167.242.146 223.3.20.186 25.181.180.99 2.55.199.32 (3 Replies)
Discussion started by: lewk
3 Replies

8. 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

9. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies
clear_wait(9r)															    clear_wait(9r)

NAME
clear_wait - General: Clears the wait condition SYNOPSIS
void clear_wait( thread_t thread, int result, boolean_t interrupt_only ); ARGUMENTS
Specifies a pointer to the thread Specifies the outcome of the wait. You can pass one of the following values: This is a normal wakeup. The timeout period expired. The clear_wait routine interrupted the wakeup. Specifies a Boolean value that indicates how the clear_wait routine clears the wait condition. You can pass one of the following values: Clears the wait condition only if the kernel thread is waiting in an interruptible state. Clears the wait condition under any circumstances. DESCRIPTION
The clear_wait routine clears the wait condition for the specified kernel thread and starts executing the kernel thread, if appropriate. If the kernel thread is interruptible and is still waiting for the event, clear_wait sets the kernel thread state to TH_RUN and places it on the run queue. RETURN VALUES
None SEE ALSO
Routines: assert_wait_mesg(9r), mpsleep(9r), thread_block(9r), thread_wakeup(9r), thread_wakeup_one(9r) clear_wait(9r)
All times are GMT -4. The time now is 05:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy