Error running job using shell script.

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
Kel
Participant
Posts: 31
Joined: Mon May 11, 2015 3:20 am
Location: Robinsons Cybergate Tower 2
Contact:

Error running job using shell script.

Post by Kel »

Hi. I have a simple source>join>target parallel job and when I run it on the Datastage it works fine, but when I run it using shell script it is returning errors. I'm currently on a much complex requirement where I should run 2 sequences using a shell script and trying my code on a smaller job before implementing. Can you point out if there are errors in the code.

Code: Select all

# Initialize enviromental parameters to use Datastage commands.

cd /opk/IBM/InformationServer/Server/DSEngine
. ./dsenv > /dev/null 2>&1

#"Project Name"
Vambiente=DESA_HUB_NAL
	
	
# Name of the jobs that will be executed
VstrJob1=Using_Join

#Identify the status of the Datastage Job.		
VmsgJobstatus=`dsjob -jobinfo $Vambiente $VstrJob1 | grep "Job Status" | cut -c14-20`

#Check status, if the last State was failed or stopped then reset the Job
if [ "$VmsgJobstatus" = "RUN FAI" ] || [ "$VmsgJobstatus" = "STOPPED" ]; then
	echo " ... Resetting JOB: "$VstrJob1
	dsjob -run -mode RESET  $Vambiente $VstrJob1
fi
	
# Estimated date with hours and seconds to display the start time of execution
VfechaIni=`date +"%d%m%Y-%H:%M:%S"`

# Executes the job
dsjob -run -jobstatus $Vambiente $VstrJob1 


if [ "$OUT" = "1" ]; then
		Vmens=" The process ended successfully. "
		echo $Vmens
		Vest="OK"
		VfechaFin=`date +"%d%m%Y-%H:%M:%S"`
OUT=0
		

elif [ "$OUT" = "2"  ]; then			
		Vmens=" The process ended successfully, but there are warning for reviewing. "
		echo $Vmens
		Vest="WARNINGS"
		VfechaFin=`date +"%d%m%Y-%H:%M:%S"`

OUT=0


else
		Vmens=" The process ended with errors."
		echo $Vmens
		Vest="FAILED"
		VfechaFin=`date +"%d%m%Y-%H:%M:%S"`
fi  
The script returns the following after execution
Status Code = 0
Waiting for job....
Finished waiting for job
Job status : (1)

Status code = 1
The process ended with errors.

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

Post by chulett »

Look up what the jobstatus option does for the return codes. 1 = Ran OK, for example... which you seem to be expecting. Looks like an issue with $OUT as I don't see you setting that anywhere, only testing for it.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Your script sets the variable OUT, but does not reflect this when exiting. All you need is to add exit $OUT at the end of your script.

If that doesn't work, try using the shell variable $? instead.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

ray.wurlod wrote:Your script sets the variable OUT
Where? I see the first mention of it in the test for success and it's not set until after the first test for it. And since it is not set, it never passes the "=1" or "=2" test so the "OUT=0" bits never run.

Seems to me that's what is going on, anywho.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

I think that the = 1 or = 2 tests may have succeeded, but the value returned by them was never transferred to the exit status of the enclosing script itself, hence the advice I tendered.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Kel
Participant
Posts: 31
Joined: Mon May 11, 2015 3:20 am
Location: Robinsons Cybergate Tower 2
Contact:

Post by Kel »

Hi. I tried setting OUT = $? , removing the double quotes on the $OUT in the if statements and running again but now I'm getting this output:

Status Code = 0
Waiting for job...
Finished Waiting for job
Job Status : (1)

Status Code = 1
aa.sh [36]: OUT: not found
aa.sh [38]: test: 0403-004 Specify a parameter with this command.
aa.sh [46]: test: 0403-004 Specify a parameter with this command.
The process ended with errors.

I've read a previous post in here that status code 1 means that the job is running. But I want the script to echo that the job has been executed successfully. Any advice with be appreciated.
BOG
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

With the jobstatus option, that "1" return code means "Ran OK", not that it is running. Zero means running. And I stand by my diagnosis. :wink:

Post your modified script as it is obviously broken, syntax-wise.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Kel
Participant
Posts: 31
Joined: Mon May 11, 2015 3:20 am
Location: Robinsons Cybergate Tower 2
Contact:

Post by Kel »

This unix is so sensitive :3. What I did was declared:
OUT = $ (With space)
and there's the OUT not found error.

When I removed the spaces:
OUT=$
It finally echoed the correct message.


Thanks for all your Inputs. Clicking mark as resolved. :D
BOG
Post Reply