Shell Scripting Function call return value


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Scripting Function call return value
# 1  
Old 06-25-2012
Shell Scripting Function call return value

Hi I have a function :

Code:
Make_Report()
{
    trx_report=`sqlplus -s $conn_str << @@
                       set echo off;
                       set pages 0;
                       set feedback off;
                       set verify off;
                       select srv_trx_s_no, subscriber_no,
                       to_char(SYS_CREATION_DATE,'MM/DD/YYYY HH24:mi:ss')
                       from q1 where rownum <=5 order by 1
                       ;
                       @@`
}

If there are no rows return by this function i want to stop my execution there and no email should be sent , but if some rows are retuned by this function i want to send a alert email , i tried using $? , but no luck , please help.

Last edited by Scott; 06-25-2012 at 02:26 AM.. Reason: Code tags
# 2  
Old 06-25-2012
I suggest adding this statement right before your 'select' statement:
Code:
whenever sqlerror exit 1


and this statement right after your 'select' statement:
Code:
exit 0


and then right after this statement '@@`' check your return code with some shell code like this:
Code:
if [[ $? = 1 ]] then
  print `date "+%Y-%m-%d-%H.%M.%S"` "..........., review above messages." >> ${LOG_FILE_PATH}${LOG_FILE}
  return
else
  # Delete leading from feed from variable
  trx_report=`print $qry_result | tr -d '\f'`
  if [[ $trx_report = 'no rows selected' ]] then
    print `date "+%Y-%m-%d-%H.%M.%S"` "*** trx_export.sh ended ***" >> ${LOG_FILE_PATH}${LOG_FILE}
    return
  else
    # Extract data from result
    data=`print $trx_report | cut -f1 -d' '`
  fi
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Segmentation fault in function call, shell script

I am getting Segmentation fault at below function call in my script: get_x() { sqlplus -s / <<end | grep KEEP | sed 's/KEEP//;s///g' select 'KEEP' ,table_name from all_synonyms where upper(synonym_name)= '$1'; exit end x=$(get_x $1) echo " SQL OUTPUT IS :: $x" } I am getting output of... (1 Reply)
Discussion started by: IB_88
1 Replies

2. Shell Programming and Scripting

How to call a function in Shell..?

#!/bin/bash FUN_ECHO(){ echo $1 } FUN_ECHO "hi how are you ?" This code will work fine. BUT is it possible to make the following to work ? FUN_ECHO "hi how are you ?" FUN_ECHO(){ echo $1 } I know that the code will be executed line by line. But i have a number of... (5 Replies)
Discussion started by: linuxadmin
5 Replies

3. Shell Programming and Scripting

Call Shell Function from mysql timestamp

Hi all, Actually my aim is to call the shell script when ever there is a hit in a mysql table which consist of 3 values. Acter some research I came to know that it is not possible and can achive with timestamp. Can someone please tell me how to read the table timestamp which should done... (3 Replies)
Discussion started by: santhoshvkumar
3 Replies

4. Red Hat

how to call a particular function from one shell another shell script

please help me in this script shell script :1 *********** >cat file1.sh #!/bin/bash echo "this is first file" function var() { a=10 b=11 } function var_1() { c=12 d=13 (2 Replies)
Discussion started by: ponmuthu
2 Replies

5. Shell Programming and Scripting

Shell Script to call another function

Here is the following code : 1. # gcc -c test firstprog.c the above command will generate a executable file called "test " in which ever directory it is run. Assuming It will also return a value. 2. In the below SCRIPT . test is a file generated by compiling a c program... (3 Replies)
Discussion started by: Vabiosis
3 Replies

6. Shell Programming and Scripting

Call Shell scripting from Perl Scripting.

Hi How to call a shell scripting through a Perl scripting? Actually I need some value from Shell scripting and passes in the Perl scripting. So how can i do this? (2 Replies)
Discussion started by: anupdas
2 Replies

7. UNIX for Advanced & Expert Users

Function call not return value into var

hi friends, I writing a script, one of the function there is: ################################### ########### Return 1 if has subfolders and 0 otherwise ################## # Get one Argument - Folder name Has_Subfolders() { count=0 cd $1 for zont in `ls -l | grep drw | awk... (4 Replies)
Discussion started by: katzs500
4 Replies

8. UNIX for Dummies Questions & Answers

Function call not return value into var

hi friends, I writing a script, one of the function there is: ################################### ########### Return 1 if has subfolders and 0 otherwise ################## # Get one Argument - Folder name Has_Subfolders() { count=0 cd $1 for zont in `ls -l | grep drw | awk... (1 Reply)
Discussion started by: katzs500
1 Replies

9. Shell Programming and Scripting

how can i call a function in shell script

i have a function written in one shell script and i want to call that function in another shell script and use the value returned by that script. can any one suggest me how can i do that? regards, Rajesh.P (4 Replies)
Discussion started by: rajesh.P
4 Replies

10. Shell Programming and Scripting

i want to call a oracle function in my shell script

i want to call a oracle function in my shell script (4 Replies)
Discussion started by: dineshr85
4 Replies
Login or Register to Ask a Question