weird return code processing changes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting weird return code processing changes
# 1  
Old 11-10-2008
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:
Code:
#!/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:
Code:
#!/usr/bin/ksh
echo Running step1
echo Something went wrong
exit 1

This works as expected from the shell prompt:
Code:
$ /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:
Code:
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
# 2  
Old 11-10-2008

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:

Code:
/tmp/sc1.ksh || exit

echo "No errors"
exit 0

# 3  
Old 11-10-2008
weird return code processing changes (AIX, ksh)

Uhh..yes, a space after the zero is required...Smilie 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!

Code:
#!/bin/ksh

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

echo "No errors"
exit 0

# 4  
Old 11-10-2008

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

Try replacing it with false.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How could I use the value of return code

Hello, I am woring on a script where I am getting strange situation.This script actually fetch the source code and tar that code and send to NAS location.This code resides in MKS tool...and we are fetching the source code on checkpoint label basis and script is working fine.First it synch the... (0 Replies)
Discussion started by: anuragpgtgerman
0 Replies

2. Programming

Parallel Processing Detection and Program Return Value Detection

Hey, for the purpose of a research project I need to know if a specific type of parallel processing is being utilized by any user-run programs. Is there a way to detect whether a program either returns a value to another program at the end of execution, or just utilizes any form of parallel... (4 Replies)
Discussion started by: azar.zorn
4 Replies

3. UNIX for Dummies Questions & Answers

What command to time processing of code

What command do I run to see how long it takes the CPU to process a line of code? (1 Reply)
Discussion started by: glev2005
1 Replies

4. Shell Programming and Scripting

return code help

Hello folks, I have a question that if i type ls command and type echo $? it always show "0", how i could do this change that when i type ls it will show me 1, actually i want to change the return code of commands from 0 to 1. Thanks Bash (5 Replies)
Discussion started by: learnbash
5 Replies

5. Shell Programming and Scripting

Need help with return code 1...

Hi Guys,, I am having a unix script which is running the DB2 Insert command. For the insert command, there were no records to be updated. SQL0100W No row was found for FETCH, UPDATE or DELETE; or the result of a query is an empty table. SQLSTATE=02000 + + echo 1 STAGE_RC=1 + ] ... (6 Replies)
Discussion started by: mac4rfree
6 Replies

6. UNIX for Dummies Questions & Answers

FTP Return Code

Hi All, I have a problem to identify the error code thrown by FTP Server while uploading files. The message is : ftp return 32. I couldn't find out what is the meaning of that. :confused: OS is Sun Solaris 2.10. Anyone can help? Thanks a lot (1 Reply)
Discussion started by: wilsonSurya
1 Replies

7. UNIX for Dummies Questions & Answers

to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 's

Hi All, Can anyone please let me know the syntax / how to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 'system()' function and '${?}'. I am in a process to send the mail automatically with an attachment to bulk users. I have used 'Mailx' and 'Unencode'... (0 Replies)
Discussion started by: manas6
0 Replies

8. Shell Programming and Scripting

asking about return code

hi all my system is linux red hat i have a script that runs some object . the object return some code to the system i see the code by writing echo $? i want to ask in the script if $? equals 14 how shell is do that in the script thanks (3 Replies)
Discussion started by: naamas03
3 Replies

9. UNIX for Advanced & Expert Users

Return code from PL/SQL Code

Hi Guys, I was just wondering if anybody can help me with this problem. OK, how we can get a value back from PL/SQL Script (not stored procedure/function) See the below example: (for example aaa.sh) #!/bin/ksh VALUE=`sqlplus -s user/password@test_id <<EOF @xxx.sq EOF` echo $VALUE ... (7 Replies)
Discussion started by: Shaz
7 Replies

10. Shell Programming and Scripting

return code from oracle

I am writing a unix script that logs into oracle and does a count on a table. I want to return that count to my unix script. this is my script: #!/bin/ksh typeset retcode; numin=0 sqlplus -s <<-EOSQL myuser/mypass@mydb variable ret_val number; begin ... (3 Replies)
Discussion started by: lesstjm
3 Replies
Login or Register to Ask a Question