weird return code processing changes

My problem is my AIX ksh script works as expected from the shell prompt, but when the same script is executed by a daemon, it fails to acknowledge any non-zero return codes for programs it executes.

I have one ksh script the calls another. The calling one is /tmp/harn.ksh:

#!/bin/ksh

/tmp/sc1.ksh
rc=$?
if [[ $rc -ne 0]]; then
 exit $rc
fi

echo "No errors"
exit 0

And a second one, "/tmp/sc1.ksh" which doesn't matter what it is as long as it exits with a non-zero return code:

#!/usr/bin/ksh
echo Running step1
echo Something went wrong
exit 1

This works as expected from the shell prompt:

$ /tmp/harn.ksh
Running step1
Something went wrong
$ echo $?
1
$ 

Now when it is executed by our daemon (long story, but shouldn't be anything funny), I get this:

Running step1
Something went wrong
No errors

Other info:

  • It is happening entirely within the ksh and that's why I don't think the daemon matters.
  • If I convert /tmp/harn.ksh to Perl, it works perfectly. That would be my solution, but this is for a customer and it's not an option.
  • /tmp/sc1.ksh can be replaced by any program creating an error and will lead to the same results.
  • I Googled and Googled and tried dozens of ways to change how the return code is captured and processed all with the same results.
  • I thought maybe the difference was due to not having a tty attached to the script executed by the daemon. I slipped a tty command at the beginning of each script and got /dev/pts/3 for both instead of /dev/pts/2 at the shell prompt (honestly, i don't fully understand that - looks like it attached a pseudo-terminal or something)

Thanks

I suspect that you did not copy the script correctly, becuase there is a syntax error in the one you posted.

What happens with this script:

/tmp/sc1.ksh || exit

echo "No errors"
exit 0

Uhh..yes, a space after the zero is required...:o Thanks for the suggestion, but same problem.

I was thinking maybe to try executing through ssh, but don't have that on this box. Yep, low tech, like not being able to copy and paste correctly!

#!/bin/ksh

/tmp/sc1.ksh
rc=$?
if [[ $rc -ne 0 ]]; then
 exit $rc
fi

echo "No errors"
exit 0

Are you sure that /tmp/sc1.ksh fails?

Try replacing it with false.