Run a script continuously for 10 minutes

Hi all!!

Im using ksh and my OS is Linux.

I want to run a script for ten minutes, starting from my current system time.

How to acheive this?

Any help appreciated.

Thanks in advance

Some info about what the script is supposed to do for 10 minutes would help.

do_stuff&
pid=$?
sleep 600
kill $pid
wait $pid

$? is the exit code of the previous command, which for a backgrounded process would always be 0.

Although I presume you mean $! :slight_smile:

You could also just kill it using the job number:

./myScript &
sleep 600
kill %1

If you want to kill the current script after 10 minutes just run another script in background with nohup. pass the parent process id(current script id) and in that script just wait for 10 mins

current_script.ksh
#!/bin/ksh
nohup monitor.ksh $$ >> some_log_file 2>&1 &

your code
.....
.......
<end of script>

monitor.ksh

#!/bin/ksh
PP_ID=$1

sleep 10m

kill -9 $PP_ID

exit 1

hope it works.

Hi.

Some systems have:

Best wishes ... cheers, drl