bash scripting try something, but quit if it's taking too long
Chris F.A. Johnson
chris-E7bvbYbpR6jSUeElwK9/Pw at public.gmane.org
Wed Jun 23 01:42:38 UTC 2010
On Tue, 22 Jun 2010, Matt Price wrote:
> 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)
while ps returns a zero exit code (0 == successful)
> 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
>
--
Chris F.A. Johnson, <http://cfajohnson.com>
Author:
Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
--
The Toronto Linux Users Group. Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists
More information about the Legacy
mailing list