Shell command execution always giving zero as return value


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell command execution always giving zero as return value
# 1  
Old 07-04-2012
Shell command execution always giving zero as return value

Whenever the shell script is invoked by the scheduler the command execution return code is always captured as 0(Success).
If the same shell script is executed in command line via unix terminal, the command execution return code's are captured properly.

For example:
ls -ltr es_wrong_file ----> file not available in the filesystem
echo $? ----> return code $? will be 2(other than 0)

If the above example is executed via scheduler (which in turn invokes the script) - the return code is captured as 0 (success)
whereas if its a directly command line execution of the same script then the return code is captured properly as "2"

---------- Post updated at 06:43 AM ---------- Previous update was at 06:40 AM ----------

Oracle scheduler is used
Unix flavor is AIX6.1
shell used - ksh
# 2  
Old 07-04-2012
It is coming as 2 only. I have tried few ways still i m getting 2 only. Better if you put your code..
# 3  
Old 07-04-2012
Hi,

If the shell script is run in command line you will get it as 2...

but the same shell script when it is invoked by oracle scheduler - the return code is 0
# 4  
Old 07-04-2012
I don't have oracle scheduler here on my system. But if that is not working you can use below code if you are just checking the presence of file.

Code:
if [[ -e file ]]
then
echo "pass"
else
echo "fail"
fi

# 5  
Old 07-04-2012
Quote:
Originally Posted by vemal
Whenever the shell script is invoked by the scheduler the command execution return code is always captured as 0(Success).
If the same shell script is executed in command line via unix terminal, the command execution return code's are captured properly.

For example:
ls -ltr es_wrong_file ----> file not available in the filesystem
echo $? ----> return code $? will be 2(other than 0)

If the above example is executed via scheduler (which in turn invokes the script) - the return code is captured as 0 (success)
whereas if its a directly command line execution of the same script then the return code is captured properly as "2"
It could simply mean that your script generates the file "es_wrong_file" at run-time and ls is able to list it at that particular time. Check if this file is being written to in your script. This could also be an intermediate file which your script could be cleaning up before termination.

So, don't leave people guessing and post the script if you can.
# 6  
Old 07-04-2012
The script would have to exit with a non-zero exit code.

Code:
ls -ltr es_wrong_file ; REPLY=$?
exit ${REPLY}

It would indeed be better to test whether the file exists rather than letting the command fail. Use syntax appropriate to your O/S (many do not have "-e").
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep command giving different result for different users for same command

Hello, I am running below command as root user #nodetool cfstats tests | grep "Memtable switch count" Memtable switch count: 12 Where as when I try to run same command as another user it gives different result. #su -l zabbix -s /bin/bash -c "nodetool cfstats tests | grep "Memtable switch... (10 Replies)
Discussion started by: Pushpraj
10 Replies

2. HP-UX

Find command doesn't return in shell script.

Hi All, I am using below snippet to search for a string (read from a file 'searchstring.out') in all locations (/) and then iterate over the files found to write the locations and the respective owner to an output file. However, this doesn't work as I believe the find command doesn't exit's... (11 Replies)
Discussion started by: Vipin Batra
11 Replies

3. Shell Programming and Scripting

Sql command inside shell script runs without giving anything back as outout

#!/bin/sh # This script returns the number of rows updated from a function echo "The execution is starting ....." sqlplus -silent $UP <<EOF set serveroutput on set echo off set pagesize 0 VAR no_rows_updated NUMBER; EXEC :no_rows_updated :=0; DECLARE CURSOR c_update is SELECT * FROM... (4 Replies)
Discussion started by: LoneRanger
4 Replies

4. Shell Programming and Scripting

How to exit a shell script if a unix command does not return any value for 10 seconds?

Hi, Can anyone help me how to exit a shell script if a unix command inside does not return any value for 10 seconds? The scenarios is like this. I want to login to a application using shell script where the connection string is mentioned.but suppose this connection string is not... (10 Replies)
Discussion started by: arijitsaha
10 Replies

5. Shell Programming and Scripting

Shell Command execution through PERL

Hi Guys, I wish to execute some shell commands through PERL. Here is what I desire to do 1) I wish to find list of directories in current working location 2) Then go in each directory and execute few commands like a) rm -rf *.log (Shell command) b) coreBuilder -f cb_tests.tcl (Some... (6 Replies)
Discussion started by: hardik_snps
6 Replies

6. Shell Programming and Scripting

Need to return fail or pass from shell script on the basis of pl/sql code execution

Hi guys, I am quite new in shell scripting. I am tring to promote some oracle jobs into control-M. In control-M, I am calling a script which establishes a connection with database and execute some procedures. Now I want if that PL/sql Block got failed script should return failure to... (2 Replies)
Discussion started by: alok1301
2 Replies

7. Shell Programming and Scripting

In ksh shell command - Print "-ABC" is giving error

Hi Guys, while executing the following command : print "-ABC" is giving following error : ksh: print: bad option(s) I cannot use echo for some other reasons, so any other option ? (2 Replies)
Discussion started by: sagarjani
2 Replies

8. Linux

Terminal Execution By Giving a Command

Hi Guys, I am using Red Hat Linux 5 and GNOME Terminal is available there in the Accessories menu of Applications. But I don't see any run command option which can be used to type the name of the terminal and execute it directly as I used to do it under Mandrake Linux wherein I would type... (2 Replies)
Discussion started by: indiansoil
2 Replies

9. 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

10. Shell Programming and Scripting

mv command is giving error in shell script

Hi, In my shell script when I am using mv command using shell variables it is giving me error of syntax. Following is the shell script: file_edifice="*.txt" fquote="'" fdquote=\" for file in $file_edifice do file_name=$fquote$file$fquote tofile_name=`date... (5 Replies)
Discussion started by: gammit
5 Replies
Login or Register to Ask a Question