simple shell script

Beecher Rintoul akbeech at gmail.com
Wed Dec 7 21:17:07 PST 2005


On Wednesday 07 December 2005 07:33 pm, Martin Cracauer wrote:
> 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

Thanks to you both, I missed the background option. Actually it just needs to 
run in the background to log some hits on a free webserver that I use for 
testing. I forget and they will cancel my account if there's no traffic for a 
month. The timeout also looks interesting and I'll look into it.

Beech

-- 

---------------------------------------------------------------------------------------
Beech Rintoul - System Administrator - akbeech at gmail.com
/"\   ASCII Ribbon Campaign  | NorthWind Communications
\ / - NO HTML/RTF in e-mail  | 201 East 9th Avenue Ste.310
 X  - NO Word docs in e-mail | Anchorage, AK 99501
/ \  - Please visit Alaska Paradise - http://akparadise.byethost33.com
---------------------------------------------------------------------------------------











-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20051207/1d8afe6a/attachment.bin


More information about the freebsd-questions mailing list