Help of Whence


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help of Whence
# 1  
Old 07-29-2013
Help of Whence

Hi,

When i try to execute this particular script it gives out error.
Can anyone help me out what is the issue here.

Code:
Error:
=====
++ whence sqlplus
abc.ksh: line 14: whence: command not found
+ S=
+ [[ -z '' ]]
+ echo sqlplus does not exist
sqlplus does not exist

Code:
Script:
=======
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/sbin:/opt/java/bin:/opt/abc/oracle/bin/
export LD_LIBRARY_PATH=/opt/abc/oracle/lib

S=$(whence sqlplus)
if [[ -z "$S" ]];then
        echo sqlplus does not exist
        exit
fi

rm -f  /var/tmp/abc.tmp
rm -f  /var/tmp/abc.msg
dte=`date`

sqlplus -s /NOLOG @/var/prod/Murali/abc.sql |grep -iv connect 1> /var/tmp/abc.tmp 2>&1

abc_cnt="$(awk -F: '/ABC_fail/{print $2}' /var/tmp/abc.tmp  | sed 's/ //')"

echo ${abc_cnt}

if [[ ${abc_cnt} -ge 1 ]]

then
    echo "record found around ${dte}  " > /var/tmp/abc.msg
    sqlplus -s /NOLOG @/var/prod/abcfail.sql |grep -iv connect 1>> /var/tmp/abc.msg 2>&1
    
    cat /var/tmp/abc.msg | mailx -s "record not processed, please check and process it"  "abc1@build.com"

fi

I'm expecting the script to connect to the SQL file
Code:
/var/prod/Murali/abc.sql

# 2  
Old 07-29-2013
The error has nothing to do with SQLPLus missing, but with whence. Try using which instead of whence.
This User Gave Thanks to Scott For This Post:
# 3  
Old 07-30-2013
Thank you Scott.

Script is now running with "which".
Can you tell me why it was not executing with "whence"
# 4  
Old 07-30-2013
whence is a Korn shell built-in (it's also available in zsh and maybe other shells, but not in Bash).
# 5  
Old 07-30-2013
Scott,

I'm able to connect to the DB. Now the script is not executing . It is not showing any errors as well.
In my script "do.sql" is returning the count. However the script is not reading further down " if [[ ${fail_cnt} -ge 1 ]] ". Script and Debug output below.

Code:
SCRIPT :
========

dte=`date`
sqlplus -s /NOLOG @/var/Murali/do.sql |grep -iv connect 1> /var/tmp/do.tmp 2>&1

fail_cnt="$(awk -F: '/MSG_fail/{print $2}' /var/tmp/do.tmp  | sed 's/ //')"
echo ${fail_cnt}
if [[ ${fail_cnt} -ge 1 ]]
then
    echo "Error record found around ${dte} and the count is around ${fail_cnt}." > /var/tmp/redo.msg
    sqlplus -s /NOLOG @/var/Murali/failcount.sql |grep -iv connect 1 >> /var/tmp/redo.msg 2>&1

    cat /var/tmp/redo.msg | mailx -s "record not processed, please check and process it"  "abc@xyz.com"
fi

Code:
Debug Output :
==========
sh -x redo.ksh  --- Debug O/P

+ dte='Tue Jul 30 05:24:35 PDT 2013'
+ sqlplus -s /NOLOG @/var/Murali/do.sql
+ grep -iv connect
+ 1> /var/tmp/do.tmp 2>& 1
+ awk -F: '/MSG_fail/{print $2}' /var/tmp/do.tmp
+ sed 's/ //'
+ fail_cnt=''
+ echo
+ [[ '' -ge 1 ]]

prd:/var/Murali]>

# 6  
Old 07-30-2013
Quote:
Originally Posted by murali1687
...Now the script is not executing . It is not showing any errors as well.
In my script "do.sql" is returning the count. However the script is not reading further down " if [[ ${fail_cnt} -ge 1 ]] ". Script and Debug output below.

Code:
SCRIPT :
========

dte=`date`
sqlplus -s /NOLOG @/var/Murali/do.sql |grep -iv connect 1> /var/tmp/do.tmp 2>&1

fail_cnt="$(awk -F: '/MSG_fail/{print $2}' /var/tmp/do.tmp  | sed 's/ //')"
echo ${fail_cnt}
if [[ ${fail_cnt} -ge 1 ]]
then
    echo "Error record found around ${dte} and the count is around ${fail_cnt}." > /var/tmp/redo.msg
    sqlplus -s /NOLOG @/var/Murali/failcount.sql |grep -iv connect 1 >> /var/tmp/redo.msg 2>&1

    cat /var/tmp/redo.msg | mailx -s "record not processed, please check and process it"  "abc@xyz.com"
fi

Code:
Debug Output :
==========
sh -x redo.ksh  --- Debug O/P

+ dte='Tue Jul 30 05:24:35 PDT 2013'
+ sqlplus -s /NOLOG @/var/Murali/do.sql
+ grep -iv connect
+ 1> /var/tmp/do.tmp 2>& 1
+ awk -F: '/MSG_fail/{print $2}' /var/tmp/do.tmp
+ sed 's/ //'
+ fail_cnt=''
+ echo
+ [[ '' -ge 1 ]]

prd:/var/Murali]>

It does not show any errors because ${fail_cnt} which is '' is not greater than or equal to 1, and the control does not go inside the if branch. There is nothing erroneous about that.

You'll have to investigate your "do.tmp" file.
Maybe the file is empty?
Or maybe it is not empty but it does not have the text "MSG_fail", due to which awk does not report anything?
This User Gave Thanks to durden_tyler For This Post:
# 7  
Old 07-30-2013
Thank you durden_tyler & scott. My script is executing now.
I corrected my sql script. It had ""MSG_count" instead of "MSG_fail".
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question