Error while executing shell script from After-Job subroutine

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
sumesh.abraham
Participant
Posts: 153
Joined: Thu May 11, 2006 1:52 am
Location: Bangalore

Error while executing shell script from After-Job subroutine

Post by sumesh.abraham »

I am trying to a count check between records fetched from source table and records loaded to target table for an audit purpose. What I am trying to do is writing the record count from source and target to sequential files and run a diff command in the After-Job subroutine using ExecSH. But, I get an error as below:

Code: Select all

diff file1 file2; if [ $? == 0 ] then echo "Counts in sync" else exit -1 fi
When I run the job, I get warning as
SH: Syntax error at Line 1 : `if' is not matched.

My search in the forum did not fetch any specific solution. Apprecite your help!
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

I wonder if escaping might help here:

Code: Select all

diff file1 file2; if \[ $? == 0 \] then echo "Counts in sync" else exit -1 fi 
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

I'm assuming that if you run this manually from the command line directly, it doesn't give you that error, yes?
-craig

"You can never have too many knives" -- Logan Nine Fingers
sumesh.abraham
Participant
Posts: 153
Joined: Thu May 11, 2006 1:52 am
Location: Bangalore

Post by sumesh.abraham »

Thanks for the replies. Escaping the script in After-job subroutine did not help. I executed the script successfully from command line as below.

Code: Select all

#!/usr/bin/ksh
diff file1 file2
if \[ $? == 0 \]; then 
 echo "Counts in sync" 
else 
exit -1 
fi 
But, when I run the script as After-job subroutine, there is an error.

Code: Select all

Syntax error at Line 1 : 'Then is not expected'
[quote][/quote]
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Does the script also work as a 1-liner in the command line?

Can you write the script to accept arguments and pass only the arguments to the after-job routine? That way would certainly work.
Post Reply