Let me establish first the fact that this is primarily designed to address the current setup of jobs that we're monitoring. We already know when it'll be executed so the list is pre-arranged according to time of execution. From which I have considered the changes that I did. And as always, this is a work in progress so bear with me.
First change that I did was to add a couple of lines in the JOB_CHECKER function after the SU_MAILER.
cp -p JOBLIST.txt TEMP.out
sed '1d' TEMP.out > JOBLIST.txt
It deletes job 1 from the JOBLIST.txt as not to waste time when doing a FOR-loop for jobs already marked as SU. It's kinda lame really but am looking for better way to cleanup this mess.
The second one is changing the condition in JOB_CHECKER function.
if [ "$DONE_JOB" = "$ONQUEUE_JOB" ]
was changed to [and DONE_JOB is removed]:
if grep -w $ONQUEUE_JOB EXCLUDEJOB.txt
Third is on WHILE-loop. The script exits when there's nothing left [to read] in the JOBLIST.txt. Hence, COUNTER is no longer needed.
while [ "$NO_JOBS" -gt "0" ]
...
It's still consuming a lot of CPU and I haven't figure this one out yet. To allow "others", after a FOR-loop, I put the script into sleep.
And lastly, a safety net was added in the SU_MAILER function. It'll erase duplicate entries from the exclusion list.
SU_MAILER() {
/sbcimp/run/tp/CA/Autosys/v4.0/bin/autorep -J $JOBNAME | grep $JOBNAME | awk '{sub (/:/,""); print $1$2$3}' >> EXCLUDEJOB.txt
awk '!x[$0]++' EXCLUDEJOB.txt > EXCLUDEJOB.txt
/sbcimp/run/tp/CA/Autosys/v4.0/bin/autorep -J $JOBNAME | grep $JOBNAME | awk '{sub (/:/,""); print $1$2$3}' >> EXCLUDEJOB.txt
awk '!x[$0]++' EXCLUDEJOB.txt > EXCLUDEJOB.txt
I hope I'm on track on improving my scripting skills; always looking forward for a new challenge.
********
This part was added on 15 April, 2009 at 21:33 SST.
The variable $NO_JOBS was removed. Instead, its value was placed in the WHILE-loop. It was late when I found out that it is NOT being updated. Also, there are times when some of the jobs listed may be invalid for one reason or another. With this, condition was added as well. So the code will be:
while [ `cat JOBLIST.txt | wc -l` -gt "0" ]
do
for JOBNAME in `cat JOBLIST.txt`
do
if /sbcimp/run/tp/CA/Autosys/v4.0/bin/autorep -J $JOBNAME | grep "Invalid Job Name" 2>&1 > /dev/null
then
cp -p JOBLIST.txt VALJOB.out
sed -e "\|^$JOBNAME\$|d" VALJOB.out > JOBLIST.txt
continue
fi
...
done
exit $E_DONE
SU_MAILER () is still in the works. I still can't find how to delete duplicate entries while leaving one of them. The "awk" part that previously used was scrapped. It's NOT up to the job. Of course, it's my fault. ;)
I really hope I'll have the flame to continue on this for I started on my new job and is being "forced" to take on Perl which seems great. Now I know that it ain't a scripting language but rather on the grey area between interpreted and compiled. Still a long wayyyyyy. See'ya round.
One of the best ways is to upload your profile in this job site. so that you can get your dream job without much effort. This job site includes the fresher jobs in India and vacancies in Indian cities like Mumbai, Chennai, Bangalore etc.
ReplyDelete