Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 20 Jun 2001 22:24:26 +0200
From:      Marian Cerny <cernm0bm@st.ms.mff.cuni.cz>
To:        Petko Hristov Popadiyski <petko_bg@yahoo.co.uk>
Cc:        freebsd-newbies@FreeBSD.org
Subject:   Re: Time execution command?
Message-ID:  <20010620222426.A15793@artax.karlin.mff.cuni.cz>
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 %2B0100
References:  <000e01c0f0b5$cca8b850$f3acdd3f@airscapenet.com> <20010620155800.14910.qmail@web4206.mail.yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help
> 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




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