From owner-freebsd-questions@FreeBSD.ORG Thu Dec 8 04:35:22 2005 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A5DF816A41F for ; Thu, 8 Dec 2005 04:35:22 +0000 (GMT) (envelope-from cracauer@schlepper.zs64.net) Received: from schlepper.zs64.net (schlepper.zs64.net [212.12.50.230]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4F23943D81 for ; Thu, 8 Dec 2005 04:35:17 +0000 (GMT) (envelope-from cracauer@schlepper.zs64.net) Received: from schlepper.zs64.net (schlepper [212.12.50.230]) by schlepper.zs64.net (8.13.3/8.12.9) with ESMTP id jB84Xx6M036507; Thu, 8 Dec 2005 05:33:59 +0100 (CET) (envelope-from cracauer@schlepper.zs64.net) Received: (from cracauer@localhost) by schlepper.zs64.net (8.13.3/8.12.9/Submit) id jB84Xxtn036506; Wed, 7 Dec 2005 23:33:59 -0500 (EST) (envelope-from cracauer) Date: Wed, 7 Dec 2005 23:33:59 -0500 From: Martin Cracauer To: Dan Nelson Message-ID: <20051207233359.B36369@cons.org> References: <200512071847.05393.akbeech@gmail.com> <20051208035255.GD33064@dan.emsphone.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20051208035255.GD33064@dan.emsphone.com>; from dnelson@allantgroup.com on Wed, Dec 07, 2005 at 09:52:55PM -0600 Cc: freebsd-questions@freebsd.org, Beecher Rintoul Subject: Re: simple shell script X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Dec 2005 04:35:22 -0000 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 http://www.cons.org/cracauer/ FreeBSD - where you want to go, today. http://www.freebsd.org/