Waiting for things
From FBSD_tips
Waiting for something to happen or, if you can grep(1) for it you can wait for it.
Sometimes you have to wait for something to happen in the system before you can proceed to another task. This is farily easy to spot manually, but what if you want to automate things? Well, grep will exit with '0' if it gets what you are are grepping for. Suppose I wanted to wait until a mirror was rebuilt before I went ahead with some task.
Gmirror status will tell us what we want to know.
# gmirror status
Name Status Components
mirror/gm0 COMPLETE ad0
ad1
Grep will find this for us too.
# gmirror status | grep COMPLETE mirror/gm0 COMPLETE ad0
And even simpler, the exit code can be read.
# gmirror status | grep COMPLETE > /dev/null # echo $? 0
So we can loop on the the grep in an until structure, when it becomes true it will go on. The 'sleep 1' is just to keep from hammering the system too much, adjust according to the situation.
until sleep 1; gmirror status | grep COMPLETE > /dev/null do echo "done" done
Gongo 19:44, 16 October 2007 (UTC)
