Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2003
    Location
    Raleigh, NC
    Posts
    6

    Unhappy Unanswered: 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.

  2. #2
    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

  3. #3
    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?

  4. #4
    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;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •