From owner-freebsd-newbies Wed Jun 20 14:16: 5 2001 Delivered-To: freebsd-newbies@freebsd.org Received: from artax.karlin.mff.cuni.cz (artax.karlin.mff.cuni.cz [195.113.31.125]) by hub.freebsd.org (Postfix) with ESMTP id 6F8B237B408 for ; Wed, 20 Jun 2001 14:15:56 -0700 (PDT) (envelope-from cernm0bm@artax.karlin.mff.cuni.cz) Received: (from cernm0bm@localhost) by artax.karlin.mff.cuni.cz (8.9.3/8.9.3/Debian 8.9.3-21) id WAA20263; Wed, 20 Jun 2001 22:24:26 +0200 Date: Wed, 20 Jun 2001 22:24:26 +0200 From: Marian Cerny To: Petko Hristov Popadiyski Cc: freebsd-newbies@FreeBSD.org Subject: Re: Time execution command? Message-ID: <20010620222426.A15793@artax.karlin.mff.cuni.cz> References: <000e01c0f0b5$cca8b850$f3acdd3f@airscapenet.com> <20010620155800.14910.qmail@web4206.mail.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20010620155800.14910.qmail@web4206.mail.yahoo.com>; from petko_bg@yahoo.co.uk on Wed, Jun 20, 2001 at 04:58:00PM +0100 Sender: owner-freebsd-newbies@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org > Is there a command , excepting crontab, which can stop > execution of other command. For example I want to stop > ppp 2 hours after I have start it. It can be made with > crontab but it is inconvenient. If I would like to do something like that, I would do it with a shell script. I made one: --- SCRIPT #!/bin/sh # # run command on background and after specified time # stop the command # BUG: if the command finishes on its own, than # it writes some info about terminating # if parameter count ($#) is <= 2 if [ $# -le 2 ]; then echo "usage: $0 sec_to_wait command" >&2 exit 1 fi # run sleep on background and save its PID ($!) sleep $1 & sleepPID=$! # shift parameters left shift # run command on background (+ if it finishes kill sleep command) # and save its PID ( eval $* ; kill $sleepPID 2> /dev/null) & procPID=$! # wait for sleep to finish wait $sleepPID # test if the command was killed or finished on its own if kill $procPID 2> /dev/null; then echo "Procces killed" else echo "Procces finished" fi --- SCRIPT END But I have problem with some info about termination. It can be solved like that: script 20 echo hi \; sleep 10 \; echo end 2> /dev/null ^^^^^^^^^^^^ I'm not sure it will help you, but thats the way, I will do it. Maybe it can be done more easyly, but I'm not UNIX guru :-). hope it will help a bit. -- Marian Cerny cerny@spnv.sk To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-newbies" in the body of the message