Page 1 of 1

Shell script from a Routine

Posted: Mon Mar 16, 2009 6:16 am
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

Posted: Mon Mar 16, 2009 7:33 am
by chulett
You'd have to be a wee bit more specific about what an 'uneven result' means. :?

Posted: Mon Mar 16, 2009 8:10 am
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.

Posted: Mon Mar 16, 2009 8:50 am
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.

Posted: Mon Mar 16, 2009 10:15 am
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.

Posted: Mon Mar 16, 2009 10:19 am
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 !!!!!

Posted: Mon Mar 16, 2009 10:53 am
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.

Posted: Tue Mar 17, 2009 6:18 am
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.

Posted: Tue Mar 17, 2009 6:19 am
by Gokul
Yep Amey!

That is working.. The culprit was continue

Posted: Wed Mar 25, 2009 2:52 am
by Aquilis
Yep, Culprit was Continue itself.

Thanks to you all over there.