Cron Job to Run for 30 minutes

Hello Gurus,

I have a requirement to run a job from cron only for 30 minutes duration daily twice at 8.35 am and 20.35 pm

Can you please suggest how to schedule the job?

Thanks-
Pokhraj

There's nothing you can do to terminate a job after a period of time from within cron . You can either have the job terminate itself using e.g. a timer/counter, or you can schedule a second job after the period to kill the first one.

Hi RudiC,

Can you please suggest as how to terminate the job itself by using counter/timer?

Thanks-
Pokhraj Das

e.g. (recent) bash has the SECONDS variable; man bash :

So - try

if [ "$SECONDS" -ge 1800 ]; then exit; fi

Hi RudiC,
I am using ksh..

TERMSECOND=1800
${ORACLE_HOME}/bin/sqlplus -s "/ as sysdba" <<EOF >> ${LOGFILENAME}
set echo off
--set heading off
set feedback off
set linesize 100
column object_name format a20
select a.sid,a.serial#,c.object_name
from V\$session a,
V\$locked_object b,
DBA_objects c
where a.sid=b.session_id
and b.object_id=c.object_id
and c.object_name='W_GL_BALANCE_A';
exit
EOF

if [ ${TERMSECOND} -ge 1800] then
exit;
fi

The Above is my code which I have modified as suggested by you.
Can you please confirm this is OK.

Thanks-
Pokhraj Das

I definitely did NOT suggest that!

  • TERMSECOND is NOT the system variable SECONDS.
  • As TERMSECOND is not modified anywhere, that script will be exited when first encountering the if command.
  • There are two syntax errors in the if statement: a space missing before, and a semicolon after the ] .
  • That script will never come close to 30 min runtime (unless those were incredibly large tables).