Operating System - HP-UX
1822521 Members
2558 Online
109642 Solutions
New Discussion юеВ

Need assistance with script...

 
SOLVED
Go to solution
Shikha Punyani
Advisor

Need assistance with script...

Hi,
I created a script on Linux server. We work on a JOb scheduling tool which is TNG (very old software) just like maestro...Now I have made script to run around autoscan..autoscan in TNG means New day load (Like Jnext day in Maestro)...
Script work is to :
Checks on the TNG Tracking Database for jobs stuck in WRSRC(Waiting for resource) status. Job will start straight after Autoscan(1 AM) and run a 24-hour cyclic script with a sleep of 15 minutes between each interrogation. If the same jobs have been found in WRSRC status after 2 interrogations, then the following console message is issued:
├в CALLOUT - There are jobs stuck in WRSRC status. Investigate job log and escalate!├в

Issue is : I have made script in such a way that it should trigger at 01:00AM(Job will trigger it)...sleep for every 15 mins....and it will complete between 23:44 to 23:59)....however Job triggers it at 01:00 Am (GMt) and it completes right away...as per mt perception it should start @ 01:00 and complete @ night between 23:44 to 23: 59..
Here is the script attached:

Please assist asap...
7 REPLIES 7
Matti_Kurkela
Honored Contributor
Solution

Re: Need assistance with script...

On lines 38...49 of your script (commented "Create dummy latest file if one does not exist), the same sequence of three lines appears twice. There are three "if" statements, but only two closing "fi" keywords.

In some situations, it might be worthwhile to make a second attempt at creating the dummy latest file if the first attempt fails, but in this case, it looks more like a copy/paste mistake.

As a result of this mistake, the majority of the script would be skipped if ${latest_listfile} did exist when the script was started.

Your attached script used a very strange and un-helpful indentation scheme. I let my Vim editor re-indent it using its default indentation rules for shell scripts. The result is much easier to follow.

Vim also helped me to find the above-mentioned mistake: its syntax highlighting coloured the "done" on line 95 with white-on-red to indicate an error. The syntax highlighting keeps track of command structures like if...then...else...fi, do...done and case...esac. On line 95, it was expecting another "fi" before "done", and flagged the "done" as an error because of that.

Attached is a fixed and re-indented version of your script.

MK
MK
Shikha Punyani
Advisor

Re: Need assistance with script...

Hi,
Thanks for replying...I really need to to this one ASAp..
Apologies for my mistake.. I think I paste the old sript.. attached is the one which is on server...
Can you please have a look at it now?
Shikha Punyani
Advisor

Re: Need assistance with script...

Please check this attachment..Ignore the last one..
Shikha Punyani
Advisor

Re: Need assistance with script...

Hey I got the issue
Firstof there are two directories in it Logs and Scripts....they did not have the wrire permissions...
Now one challenge which I am facing is
Script is running when I login with sudo and type
sh -x script name....
However how can I run it as a sudo from JOb...
Job is using normal username and password
and If I will add
sudo su - in script it will wait for someone to enter password..
how do I go about it?
James R. Ferguson
Acclaimed Contributor

Re: Need assistance with script...

Hi:

> However how can I run it as a sudo from JOb

If want the 'JOb' user to be able to execute your script edit the 'sudoers' file to allow your script.

Regards!

...JRF...
Dennis Handly
Acclaimed Contributor

Re: Need assistance with script...

>Ignore the last one.

As MK mentioned please fix your indentation. This helps you and us understand your script better.

>while [ `date +%H%M` -le 2359 -o `date +%H%M` -ge 0100 ]; do

This range check isn't useful. Why not replace it by: :-)
while true; do

You probably want:
while (( $(date +%H%M) >= 0100 && $(date +%H%M) <= 2359 )); do

Note: The AND. And I usually put the lower bound first.
Your other range check seems fine.

># Pre-delete Files
>if [ -f ${old_listfile} ]

Why work so hard?
rm -f ${old_listfile}
if [ $? -ne 0 ]; then
echo "Delete of ${old_listfile} failed"
fi

Add mv -f here:
mv ${latest_listfile} ${old_listfile}

>grep "${jobset} ${job} ${jno} ${qual}" $old_listfile >>/dev/null

Better to use grep -q:
grep -q "${jobset} ${job} ${jno} ${qual}" $old_listfile

And can remove the evil cat from:
cat $latest_listfile | while read jobset job jno qual; do

while read jobset job jno qual; do
...
done < $latest_listfile
Dennis Handly
Acclaimed Contributor

Re: Need assistance with script...

>ME: while (( $(date +%H%M) >= 0100 && $(date +%H%M) <= 2359 )); do

You may have to change 0100 to 100, the posix shell may convert this to stinkin' octal.