If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > How to background command piping to while read loop?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-07-04, 04:37
shapi003 shapi003 is offline
Registered User
 
Join Date: Sep 2003
Location: Raleigh, NC
Posts: 6
Unhappy How to background command piping to while read loop?

Hello,

I want to put in a startup script (ie., /etc/init.d script) a command that is run and pipes its lines to a while read loop. However, I want the command to nohup and background because it is supposed to be a startup script. I am not sure how to do this however. Here is the piece of code that has the command:

echo "Starting vxnotify..."
`/usr/sbin/vxnotify -w 30 -f -d -c -i -A` | while read code more; do
case $code in
waiting) checkDetach;;
detach) checkDetach;;
change) checkDetach;;
disconnected) checkDetach;;
esac
done

After I start the program (e.g., /etc/init.d/vxnotify) it does not return to the command prompt. I put an ampersand (&) after the -A, but it still did not drop to the command prompt. I can run /etc/init.d/vxnotify & and it does what I want, but I do not want to do this or expect other people to know that they need to do this with the script.
Reply With Quote
  #2 (permalink)  
Old 05-07-04, 08:17
praveenpr praveenpr is offline
Registered User
 
Join Date: Jan 2004
Location: Singapore
Posts: 89
Give a name to the shell script and run at backgounr for eg:

do_proc.sh &
__________________
Thanks and Regards,

Praveen Pulikunnu
Reply With Quote
  #3 (permalink)  
Old 05-07-04, 08:34
shapi003 shapi003 is offline
Registered User
 
Join Date: Sep 2003
Location: Raleigh, NC
Posts: 6
Cool oie, move start/stop/restart, yuck

I would then have to make another script with the start/stop/restart case statement that calls just the script and remove all of the start/stop/restart from the original script. Isn't there a way to background this script within the script itself? Why didn't adding the ampersand (&) do the trick? If it didn't because the while/read is in the foreground, can you put a while...done into the background?
Reply With Quote
  #4 (permalink)  
Old 05-07-04, 14:56
vgersh99 vgersh99 is offline
Registered User
 
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
......
/usr/sbin/vxnotify -w 30 -f -d -c -i -A |&
while read -p code more; do
........
done;
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On