Page 1 of 1

Error while executing shell script from After-Job subroutine

Posted: Thu Oct 04, 2012 6:08 am
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!

Posted: Thu Oct 04, 2012 6:26 am
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 

Posted: Thu Oct 04, 2012 7:00 am
by chulett
I'm assuming that if you run this manually from the command line directly, it doesn't give you that error, yes?

Posted: Thu Oct 04, 2012 8:13 am
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]

Posted: Thu Oct 04, 2012 8:42 am
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.