I am new to Shell Scripting and I need help to write the following script in a different format...
This is the current script:
#!/usr/bin/ksh
environment=rms
export environment
. $AW_HOME/RETEK/exec/RETEK_ENVAR
ls -ltr $MMPOS/RTLOG* | tr -s " " | cut -d " " -f9 >$MMHOME/oracle/proc/bin/rtlogfiles.txt
touch $MMHOME/oracle/proc/bin/prom.1
while read LINE
do
saimptlogi_running=1
. $MMHOME/awbatch/refreshsql.sh saimptlogi
echo $LINE
mv $LINE $LINE.1
Date=`date "+%m%d%y%n"`
awrun -m saimptlogi -args 1 Y $LINE.1 $MMHOME/oracle/proc/bin/bad.1 $MMHOME/oracle/proc/bin/item.1 $MMHOME/oracle/proc/bin/waste.1 $MMHOME/oracle/proc/bin/ref_item.1 $MMHOME/oracle/proc/bin/prim_variant.1 $MMHOME/oracle/proc/bin/varupc.1 $MMHOME/oracle/proc/bin/storeday.1 $MMHOME/oracle/proc/bin/prom.1 $MMHOME/oracle/proc/bin/codes.1 $MMHOME/oracle/proc/bin/error.1 $MMHOME/oracle/proc/bin/ccval.1 $MMHOME/oracle/proc/bin/storepos.1 $MMHOME/oracle/proc/bin/tendertype.1 $MMHOME/oracle/proc/bin/merchcodes.1 $MMHOME/oracle/proc/bin/partner.1 $MMHOME/oracle/proc/bin/supplier.1 $MMHOME/oracle/proc/bin/employee.1 $MMHOME/oracle/proc/bin/banner.1 $MMHOME/oracle/proc/bin/ref_mmrp.1 $MMHOME/oracle/proc/bin/igtax.1 " " Y
sleep 140
done <$MMHOME/oracle/proc/bin/rtlogfiles.txt
sleep 90
while true
do
saimptlogi_running=`awexe jq |grep saimptlogi | grep -v REJ | wc -l`
if [ $saimptlogi_running = 0 ]; then
mv ls -ltr $MMPOS/RTLOG*.1 $MMHOME/arch
break
fi
done;
Actually I want a script which will not wait for the sleep(i;e I don't want sleep option) rather it should find for the PID in the log directory
(Ex:- Jan_12.log
Mon Jan 12 01:43:48 Program: saimptlogi: PID=12409: Started by rms
Mon Jan 12 01:45:50 Program: saimptlogi: PID=12409: Thread 1 - Terminated Successfully
)and it will ensure that if the same PID will appear again then it should assume that the current program is finished, then it should execute the next program.
Bro...its not working....
I dont want the sleep option atall...
Currently because of this sleep140 even if the first job gets complete in one minute it is unnecessarily waiting for the next job....
I want a script which will not wait for the sleep rather it should execute the next job immediately once the first job completes successfully......
And to know if a job is completed successfully it should check for the PID in the log directory "abc/xyz/Jan_12.log"
(Ex:- more Jan_12.log
Mon Jan 12 01:43:48 Program: saimptlogi: PID=12409: Started by rms
Mon Jan 12 01:45:50 Program: saimptlogi: PID=12409: Thread 1 - Terminated Successfully )
and it will ensure that if the same PID will appear again then it should assume that the current program is fine.
Hey but i think in wait we have to mention the PID but here each and every job will be having different PID ..but the PPID will be same for all that is supp.6415......Since I am not an Unix expert rather am a new commer to unix...could you please elaborate how I will use the wait here in this particular script....that would be really helpfull........Thanks
BRO...wait $! is probably not the right solution and it's not working also for this particular script
What I need is instead of sleep I want few lines of code which will check for the PID in the last line(tail -1) of current_date.log file in /abc/xyz directory....and check if the same PID count is 2 then it should execute the next job....
(Ex:- more Jan_12.log
Mon Jan 12 01:43:48 Program: saimptlogi: PID=12409: Started by rms
Mon Jan 12 01:45:50 Program: saimptlogi: PID=12409: Thread 1 - Terminated Successfully )
Please have a thorough look at my initial script and help me....I need these help badly...
Maybe this will help. Run tail on the log file, use perl to scan the output. When perl sees two lines with the same PID, it executes the command provided to perl on the rest of the command line.
So instead of sleep 140 in the above mentioned script.....can I put it like this..will it work?:
cd $MMHOME/log
while
do
more $(ls -ltr|tail -1|cut -c 55-70)|grep "saimptlogi"|tail -2f|perl -ne '/PID=([0-9]+) && { $pid{$1}++; if ($pid{$1} >= 2)'
sleep 60
done
Um, no, because the tail won't exit with the -f option, and the PERL script won't exit by itself. (Also, you don't need "more" here). This is more what you're looking for
cd $MMHOME/log
logfile=$(ls -ltr|tail -1|cut -c 55-70)
if ! tail -2f $logfile |
perl -ne '/saimptlogi/ && /PID=([0-9]+):/ && do { $pid{$1}++; exit 1 if ($pid{$1} >= 2) }'
then
echo "Started"
fi
Note, it does not exit or return until the process has started!
If it's not working for you, try increasing the tail -2f to tail -4f or something. That allows more lines of backlog to be seen. But it also means you might "catch" prior running instances.
savouch_75002_20090210_20090226160640.out/appdb/product/agent/tmp/AAAjzaWJcsyntax error at -e line 1, near "; exit"
Execution of -e aborted due to compilation errors.
Started
PL/SQL procedure successfully completed.
/appdb/product/batch/rms/pos/RTLOG_GCN1.TXT
2
./saimptlogi_batch.sh[17]: ./saimptlogi: not found
syntax error at -e line 1, near "; exit"
Execution of -e aborted due to compilation errors.
Started
Also i think we should close { $pid{$1}++; exit 1 if ($pid{$1} >= 2)' .....with a } bracket ???
Is it possible to take the line count from $MMHOME/oracle/proc/bin/rtlogfiles.txt and assign it to a variable called line_cnt and then the internal loop should run till the last file count ...This will be great ...because currently even before the last job will be still running this main batch it getting finished...This should not happen actually....Only after completion of all the dependent jobs this main batch should finish....Is there any way....
Hi Otheus.....I am trying to run the above batch in appworx but the parent batch saimptlogi_batch is getting finishes soon even as the child batches saimptlogi will still be running...this should not happen.....can you please help me...how I can modify it so that the parent batch should not get finish till the last dependent job gets finishes......Please guide me....thanks....
What does $MMHOME/awbatch/refreshsql.sh look like?
Why are you using " logfile=$(ls -ltr|tail -1|cut -c 55-70)" ? Don't you know the name of the logfile? How can you be sure it is the most recently modified entry in this directory?