bash scripting try something, but quit if it's taking too long

Matt Price moptop99-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org
Wed Jun 23 01:31:23 UTC 2010


On Tue, Jun 22, 2010 at 8:47 PM, Chris F.A. Johnson <chris-E7bvbYbpR6jSUeElwK9/Pw at public.gmane.org>wrote:

>
>
> wait=5       ## seconds before timing out
> suspend_wl &   ## put function into the background
>
> while ps $! > /dev/null 2>&1 && [ $wait -gt 0 ]
> do
>  sleep 1
>  wait=$(( $wait - 1 ))
> done
> ps $! > /dev/null 2>&1 && kill $!
>
> ah, that's super!  trying to understand it, does this mean:

while (ps $! gives a nonzero result) and ($wait is greaterthan 0)
sleep, reduce wait by 1
and afterwards
check if $1 is still running, and kill it

looks great, thanks much.  i didn't really know that ps returned an exit
value!

matt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://gtalug.org/pipermail/legacy/attachments/20100622/7b5aa5ad/attachment.html>


More information about the Legacy mailing list