Need help in script

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
pradkumar
Charter Member
Charter Member
Posts: 393
Joined: Wed Oct 18, 2006 1:09 pm

Need help in script

Post by pradkumar »

Hi Everyone,

I have two jobs A and B . B should be execute after A finsihes and the job B will create a dummy file on unix server. I created a sequence job C which has A-->B .I have a requirement to
1) execute the sequence job C .
2)Interrogate for the existence of dummy file.
3)If the file doesnot exist, sleep for 5 minutes and loop back to step 1
4) If the file exists or if the number of loop exceed 5, exit out of the loop.

For this iam trying to write a unix script. Could anyone help me with the following script

#! /usr/bin/ksh

DataStage_BIN_DIR="/opt/IBM/InformationServer/Server/DSEngine/bin"
PROJECT="$1"
JOBNAME="$2"
FILENAME="/opt/etl/Projects/xxx/xxx/dummy.txt"
for L in 1 2 4 5
do
${DataStage_BIN_DIR}/dsjob -run ${PROJECT} ${JOBNAME}
STATUS=$?
if [ $STATUS -ne 0 ]
then
echo "*** DataStage error! status = $STATUS"
exit 2
fi

A="`cat $FILENAME`"
echo $A
if [ "$A" == "1" ]
then
return 0
fi

sleep 300

done

exit 1

Let me know any changes have to be made in the script , since when i tried to execute the script with command activity stage its throwing a warning script didnot finish.. It would be helpful if any one can share a sample script to solve this requirement..

Thanks in Advance
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Why would you be executing this from a Command Activity stage? Wouldn't you just run it from the command line yourself?

Biggest thing that jumps out at me: the lack of a -wait or -jobstatus option being used, so the job is started but then immediately moves on to the next line of the script. Oh, and "for L in 1 2 4 5"? :?
-craig

"You can never have too many knives" -- Logan Nine Fingers
pradkumar
Charter Member
Charter Member
Posts: 393
Joined: Wed Oct 18, 2006 1:09 pm

Post by pradkumar »

Chulett-- The reason to execute the script by command stage is -- i have a to add an activity to execute the above script after job D starts( That inserts audit record) ---> add a waitfor activity following the activity for the above script, to wait for dummy.txt, having a timeout occurrance of 5 hrs. If the file doesnot arrive after 5 hrs , send a notification , if the file has arrived i have trigger another main seq job that loads the data and delete the dummy file.

My job design should looks like

Job D---> command stage(execute the script) -->wait for file-->main seq job-->delete file -->send email.

I have to send email if file has not arrived after 5hrs.

So please throw some suggestions how can i achieve the requirement..

Thanks
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Why not just do the whole thing in a Sequence job? That script just complicates understanding and maintenance. Sure seems like you could do the whole thing between the Start/End Loop stages with a routine (or a WFF stage) to check for the existence of your file.
-craig

"You can never have too many knives" -- Logan Nine Fingers
pradkumar
Charter Member
Charter Member
Posts: 393
Joined: Wed Oct 18, 2006 1:09 pm

Post by pradkumar »

Thanks for your reply..

so my job would be like

Start loop ( 1 to 5 times)---> job sequence C(which has A and B that creates the dummy file)--->sleep for 5 minutes ---> end loop -->wff stage-->main seq job ---> successnotification..

Please correct me if iam wrong ... it would be great if you could give outline of the job design ...

Thanks in Advance
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Well... as best as I can tell, your file check will need to be inside the loop. So, perhaps:

* Start Loop (1 thru 5 step 1)
* JobActivity C
* WFF stage (0 wait)
* File not found trigger
-- Routine sleep 5
-- End Loop (continue)
* File found trigger
-- Branch out of loop
-- Main sequence job
-- success notification
* Exit from loop (no file)
-- failure notification

Something like that, anyways. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
pradkumar
Charter Member
Charter Member
Posts: 393
Joined: Wed Oct 18, 2006 1:09 pm

Post by pradkumar »

Thank you .. I will work out on this...
Post Reply