Ok...I ran a test and on my mac, everything works as it should, but not when it's spawned via dbms_scheduler on exadata....
This is the logic (it works)
This is the template:test.ksh
#!/bin/ksh
set -x
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
MAIN_DIR="/var/root/scripts"
cd $MAIN_DIR
DATE=$(date)
HOSTNAME=$(hostname)
FILE_CFG=$MAIN_DIR/simple_INSTANCE.cfg
FILE_LOG=$MAIN_DIR/simple_INSTANCE.log
sleep $(print $((RANDOM%100+1)))
typeset -i number_running=`ps -ef | grep runit_ | grep -v grep | wc -l`
if [[ $number_running -eq 1 ]]
then
echo $number_running > $FILE_LOG
nohup ./run_once_last.ksh &
fi
This is the cfg file (simple.cfg)
NCDP x y z
NCDT q r s
EDBP a b c
JUNO d e f
This code reads the template and creates as many ksh's and spawns as exists in the cfg (runit.ksh)
#!/bin/ksh
set -x
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
MAIN_DIR="/var/root/scripts"
cd $MAIN_DIR
DATE=$(date)
HOSTNAME=$(hostname)
FILE_CFG=$MAIN_DIR/simple.cfg
FILE_LOG=$MAIN_DIR/simple.log
function doit {
sed 's/INSTANCE/$1/g' < test.ksh > runit_$1.ksh
echo ${arr_cfg[@]} > runit_$1.cfg
chmod +x runit_$1.ksh
nohup ./runit_$1.ksh &
}
cat ${FILE_CFG}|grep -v '#'|while read PARAMS
do
set -A arr_cfg $PARAMS
doit ${arr_cfg[0]} ${arr_cfg[@]}
done
Here's one genned:
#!/bin/ksh
set -x
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
MAIN_DIR="/var/root/scripts"
cd $MAIN_DIR
DATE=$(date)
HOSTNAME=$(hostname)
FILE_CFG=$MAIN_DIR/simple_$1.cfg
FILE_LOG=$MAIN_DIR/simple_$1.log
sleep $(print $((RANDOM%100+1)))
typeset -i number_running=`ps -ef | grep runit_ | grep -v grep | wc -l`
if [[ $number_running -eq 1 ]]
then
echo $number_running > $FILE_LOG
nohup ./run_once_last.ksh &
fi
This is run_once_last.ksh
#!/bin/ksh
set -x
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
MAIN_DIR="/var/root/scripts"
cd $MAIN_DIR
DATE=$(date)
HOSTNAME=$(hostname)
echo imdone > imdone.txt
It appears to work here, but when I schedule the job to run in oracle's dbms_scheduler, which kicks off the base job, everything works except the count check which would kick off the run_once_last.ksh
Obviously this is just an example, but it's all about attempting to run all oracle instances rman backups simultaneously but only run one tape backup, and that after the last backup that finishes completes....
BTW, I appreciate the sounding board. I'm not much of a scripter, I just hack away...