I have a looping shell script that I would like to do two things with:

1.  send it a signal via kill that will break it out of an inner for
loop and wait for the same (or different I guess) signal to
resume/reenter the loop.

2. send it a signal that will tell it to break out of all loops close
child processes and exit nicely.

My questions are what signals would good programming practices indicate
that I use?  In my testing I used SIGINT (kill -2 ) to toggle the
looping behavior and I have not implemented the shutdown alltogether
mecnism yet.

In my testing for the looping behavior, I trapped signal 2 and call a
function that toggles a variable, $running, to yes or no and then check
at the end of the inner for loop to see if the variable is set to yes if
so, keep cruising otherwise break out of the loop and I have a test
(while loop checking and waiting 5seconds before looping and testing
again) at the top of an outer while loop that is unending.

Structure looks something like this

num=0

while [ num -eq 0 ]
    while ! $running = 'yes'
        sleep 5
    done
     for f in `cat file`
         blah blah         # this is the stuff I want to make sure is
stable before killing
         if [ ! $running = 'yes'
            break
        fi
     done
done

Is there a better way to do this?  pausing/waiting in the for loop would
be cool but it no big deal if the for loop starts back at the top

TIA

Bret



_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to