Shell script from a Routine

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
Aquilis
Participant
Posts: 204
Joined: Thu Apr 05, 2007 4:54 am
Location: Bangalore
Contact:

Shell script from a Routine

Post by Aquilis »

I have a routine which just calls the Shell script and the returned value from the script should be used for further processing.But whenever i call the script from rouitne,it results in uneven result .But the same script if I execute in unix box, it works fine.Can any body elaborate me on it's misbehavior where my routine looks like:

Code: Select all

            Cmd = '/abc/test7.sh  /home/test/xyz.csv'
      Call DSExecute('UNIX',Cmd,Output,ReturnCode)
      Call DSLogInfo ( " NavFileColFlag Routine Returns ":ReturnCode,"Routine")
      Ans=Output
Aquilis
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

You'd have to be a wee bit more specific about what an 'uneven result' means. :?
-craig

"You can never have too many knives" -- Logan Nine Fingers
Aquilis
Participant
Posts: 204
Joined: Thu Apr 05, 2007 4:54 am
Location: Bangalore
Contact:

Post by Aquilis »

I have a shell script like:

Code: Select all

flag=1
tail +2  $1 | while read LINE
do
tag=`echo $LINE | awk -F',' '{print toupper($7)}'`
chk=`echo $tag | tr "[:lower:]" "[:upper:]"`
if [ $chk = "ACCEPTED" ] ; then
continue;
else
flag=0
break
fi
done
echo $flag
This script checks for the value 'ACCEPTED' in a file for all the records.If all the records holds 'ACCEPTED' flag then script returns value as '1' else it should return '0' as output.
But when I call this through a routine it always return as '1' ,it's not at all returning '0' , when it should actaully 0.

So is there any thing gone wrong in calling the script.this script executes perfectly on unix Box.
Aquilis
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

What I'd suggest is running the script in 'debug' mode like so: Cmd = 'sh -x /abc/test7.sh /home/test/xyz.csv' and then logging the Output variable. Then you should be able to see where it is going wrong.
-craig

"You can never have too many knives" -- Logan Nine Fingers
greggknight
Premium Member
Premium Member
Posts: 120
Joined: Thu Oct 28, 2004 4:24 pm

Post by greggknight »

try using return (number) in your script.

examp
if something is true
then
return 0
else
return 1
end if

you can use any number you want in your script to identify some action that takes place in your script. Then in DS you can make a dicision based on thouse values.

currently you are receiving 1 of two things.
The script ran
or the script failed.

output captures the return code of the script. You can overide that value by setting it in your script to the value or values that you want to receive to make a decision on.
"Don't let the bull between you and the fence"

Thanks
Gregg J Knight

"Never Never Never Quit"
Winston Churchill
greggknight
Premium Member
Premium Member
Posts: 120
Joined: Thu Oct 28, 2004 4:24 pm

Post by greggknight »

flag=1
tail +2 $1 | while read LINE
do
tag=`echo $LINE | awk -F',' '{print toupper($7)}'`
chk=`echo $tag | tr "[:lower:]" "[:upper:]"`
if [ $chk = "ACCEPTED" ] ; then
continue;
else
flag=0
break
fi
done
echo $flag
return $flag

the way you are using it as long as the script runs you will always return 0
return the value of $flag !!!!!
"Don't let the bull between you and the fence"

Thanks
Gregg J Knight

"Never Never Never Quit"
Winston Churchill
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

greggknight wrote:output captures the return code of the script
Actually, that 'Output' variable captures whatever is sent to stdout by the script, which is why they 'echo $flag'. The one they named ReturnCode captures the return code.
-craig

"You can never have too many knives" -- Logan Nine Fingers
AmeyJoshi14
Participant
Posts: 334
Joined: Fri Dec 01, 2006 5:17 am
Location: Texas

Post by AmeyJoshi14 »

Hey!

Try this one out :

Code: Select all

#!/bin/ksh
 flag=5
head -2 $1 | while read LINE
do
#echo "Inside the do loop"
tag=`echo $LINE | awk -F',' '{print toupper($7)}'`
chk=`echo $tag | tr "[:lower:]" "[:upper:]"`
#echo ${chk}
if [ $chk = "ACCEPTED" ]
 then
#continue;
flag=5
else
flag=1
break
fi
done
echo ${flag}
#return $flag
return $flag
Hope this will help you out.
http://findingjobsindatastage.blogspot.com/
Theory is when you know all and nothing works. Practice is when all works and nobody knows why. In this case we have put together theory and practice: nothing works. and nobody knows why! (Albert Einstein)
Gokul
Participant
Posts: 74
Joined: Wed Feb 23, 2005 10:58 pm
Location: Mumbai

Post by Gokul »

Yep Amey!

That is working.. The culprit was continue
Aquilis
Participant
Posts: 204
Joined: Thu Apr 05, 2007 4:54 am
Location: Bangalore
Contact:

Post by Aquilis »

Yep, Culprit was Continue itself.

Thanks to you all over there.
Aquilis
Post Reply