linux - cronjob not working as intended -
this script arc_rem.sh(755 permission) added in crontab follows
00 0,3,6,9,12,15,18,21 * * * . ./.cronprofile;/biamd/arch01/usageprd/arch/arch_rem.sh >/dev/null 2>&1
and script arc_rem.sh follows
rm /biamd/arch01/usageprd/arch/old_arcs.log cd /biamd/arch01/usageprd/arch lga=`sqlplus -s tcs384160/tcs#1234 <<\eof set pagesize 0 feedback off verify off heading off echo off select max(sequence#) v$archived_log; exit; eof` echo $lga; u_limit=`expr $lga - 35`; l_limit=`expr $u_limit - 1000`; echo $l_limit; echo $u_limit; loop_var=$l_limit; while [ $loop_var -le $u_limit ]; ls /biamd/arch01/usageprd/arch/*_${loop_var}_*.arc >> /biamd/arch01/usageprd/arch/old_arcs.log; loop_var=`expr $loop_var + 1`; done; rm `cat /biamd/arch01/usageprd/arch/old_arcs.log`
i have included absolute path wherever could.
this requirement of script delete files older sequence(u_limit in above script) ,it populating old_arcs.log , doing rm on file(last line of code)
following issues noticed
1)whenever cronjob executes @ interval of 3hrs daily size of old_arcs 0 ,hence no files removed rm ,but script works fine when execute manually sh arcs_rem.sh populates old_arcs.log intended , deletes files.
2) when ps -ef|grep sh during cronjob execution time o/p follows looks many instances of same shell script running,dont know reason why , consumes more cpu
oracle 473 455 1 21:00:00 ? 335:37 sh - c . ./.cronprofile;/biamd/arch01/usageprd/arch/arch_rem.sh >/dev/null 2>&1 oracle 614 485 1 15:00:01 ? 30:01 sh -c . ./.cronprofile;/biamd/arch01/usageprd/arch/arch_rem.sh >/dev/null 2>&1 oracle 8278 8240 1 03:00:01 ? 150:37 sh -c . ./.cronprofile;/biamd/arch01/usageprd/arch/arch_rem.sh >/dev/null 2>&1 oracle 18331 18171 1 18:00:01 ? 2:36 sh -c . ./.cronprofile;/biamd/arch01/usageprd/arch/arch_rem.sh >/dev/null oracle 1845 4464 0 06:00:01 ? 0:00 sh -c . ./.cronprofile;/biamd/arch01/usageprd/arch/arch_rem.sh >/dev/null 2>&1 oracle 9887 9822 1 00:00:01 ? 189:59 sh -c . ./.cronprofile;/biamd/arch01/usageprd/arch/arch_rem.sh >/dev/null 2>&1
it helpful if tell me wrong script or crontab config , workaround
edit:
i have checked loop variables , getting updated fine,what reason infinite loops
- you should not use relative paths
./.cronprofile
in cron job commands. - from
ps
output looks cron jobs running indefinitely, or @ least long. should check infinite loop. cron not care whether script running when starting one. print$loop_var
,$u_limit
inside loop verify they're changing expected. - use more quotes™.
- don't parse
ls
output. - shell script commands not have terminated
;
. - you should use
$()
rather``
. - add
set -o errexit -o noclobber -o nounset
@ top of script enable basic error handling. should work in posix shell.
Comments
Post a Comment