Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 7 Dec 2005 23:33:59 -0500
From:      Martin Cracauer <cracauer@cons.org>
To:        Dan Nelson <dnelson@allantgroup.com>
Cc:        freebsd-questions@freebsd.org, Beecher Rintoul <akbeech@gmail.com>
Subject:   Re: simple shell script
Message-ID:  <20051207233359.B36369@cons.org>
In-Reply-To: <20051208035255.GD33064@dan.emsphone.com>; from dnelson@allantgroup.com on Wed, Dec 07, 2005 at 09:52:55PM -0600
References:  <200512071847.05393.akbeech@gmail.com> <20051208035255.GD33064@dan.emsphone.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Dan Nelson wrote on Wed, Dec 07, 2005 at 09:52:55PM -0600: 
> In the last episode (Dec 07), Beecher Rintoul said:
> > I'm trying to write a simple shell script that will launch a program
> > (in this case lynx), wait 60 seconds and then kill it. I can get it
> > to launch the program, but it seems to ignore anything after that. I
> > am not a programmer so does anyone have a suggestion on this script?
> > Any help would be appreciated.
> 
> You need to background it so your script keeps running:
> 
> #! /bin/sh
> # Launch program
> lynx &
> # Store its processid for later
> pid=$!
> # 60 seconds
> sleep 60
> # Kill backgrounded process
> kill -9 $pid

This is probably not what Beecher wants, he/she probably needs the
lynx in the foreground.

In a pure shell script that is difficult because you cannot get the
pid of a foreground process without reverting to `ps` which is not
sportish. 

It's better to use a dedicated timeoput mechanism, e.g.:
http://cracauer-forum.cons.org/forum/cratimeout.html

Then you can do `cratimeout 60000 lynx`

Martin
-- 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Martin Cracauer <cracauer@cons.org>   http://www.cons.org/cracauer/
FreeBSD - where you want to go, today.      http://www.freebsd.org/



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20051207233359.B36369>