Can't get shell parameters to pass properly to sqlplus


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Can't get shell parameters to pass properly to sqlplus
# 1  
Old 06-15-2011
Data Can't get shell parameters to pass properly to sqlplus

Gurus,

The issue I'm having is that my Shell won't accept SQL parameters properly......

Here's they way I'm running it....

Code:
applmgr@ga006hds [/home/users/applmgr/CW_Merge_Project]
=>  sh CW_MigrationDeployScript.sh apps <appspwd> <SID> '01-JAN' '31-MAR'

The process just hangs not submitting the SQL job...



Code:
#!/bin/ksh
export USAGE="USAGE: `basename $0` -e <DBUSER> <DBPASSWD> <TNSNAME> <FROM_DATE> <TO_DATE>"
if [ $# -lt 3 ]; then
echo ${USAGE}
exit 1;
fi
SCRIPTHOME=`pwd`
TMS_USER=$1
TMS_PWD=$2
TMS_DATABASE=$3
LL="${TMS_USER}/${TMS_PWD}@${TMS_DATABASE}"
FROM_DT=$4
TO_DT=$5
PARAMS="${FROM_DT} ${TO_DT}"
dow()                                                                   
{       
perl -e '
use POSIX qw(strftime);
@time=gmtime(time -(4*3600)); #=> GMT -4
$day = strftime("%A",0,0,0,$time[3],$time[4],$time[5],-1,-1,-1);
print "$day\n"'                                                            
}         
echo "$(dow `date "+%Y-%m-%d"` )"
if [[ "$(dow `date "+%Y-%m-%d"` )" = "Monday" ]]; then
YEAR="'2005'"
elif [[ "$(dow `date "+%Y-%m-%d"` )" = "Tuesday" ]]; then
YEAR="'2006'"
elif [[ "$(dow `date "+%Y-%m-%d"` )" = "Wednesday" ]]; then
YEAR="'2007'"
elif [[ "$(dow `date "+%Y-%m-%d"` )" = "Thursday" ]]; then
YEAR="'2008'"
elif [[ "$(dow `date "+%Y-%m-%d"` )" = "Friday" ]]; then
YEAR="'2009'"
elif [[ "$(dow `date "+%Y-%m-%d"` )" = "Saturday" ]]; then
YEAR="'2010'"
fi 
cd ${SCRIPTHOME}
sqlplus -s ${LL} @./RCV_SHIPMENT_HDR_LINE_PRE_OUTAGE.sql ${YEAR} ${PARAMS} > rcv_ship_hdr_line.log
echo ""
echo ""
echo ""
echo "Deployments Complete"


When I call the *.sql script manually, from Sql prompt from server, I get the expected results.


Code:
SQL> @RCV_SHIPMENT_HDR_LINE_PRE_OUTAGE.sql
Input truncated to 1 characters
Enter value for year: '2005'
old   2:   l_year varchar2(4):=&YEAR;
new   2:   l_year varchar2(4):='2005';
Enter value for start_day_month: '01-APR'
old   3:   l_start_day_month varchar2(10):=&START_DAY_MONTH;
new   3:   l_start_day_month varchar2(10):='01-APR';
Enter value for end_day_month: '30-JUN'
old   4:   l_end_day_month varchar2(10):=&END_DAY_MONTH;
new   4:   l_end_day_month varchar2(10):='30-JUN';
Updating RCV_SHIPMENT_HDR_LINE
PL/SQL procedure successfully completed.
SQL>

Anyone have any advice on how I can get the Shell to run the *.sql properly?
# 2  
Old 06-15-2011
Hangs where?
# 3  
Old 06-15-2011
One thing springs to mind. When you ran the SQL from within SQL*Plus (@RCV_SHIPMENT....), you wound up, at the end, with:

Code:
SQL>

(the SQL prompt, i.e. you're still inside SQL*Plus)

Perhaps you need to add an exit; to your SQL?

i.e.

Code:
$ cat SQL.sh

echo Hello
sqlplus -s scott/tiger @SQL.sql
echo Good bye

$ cat SQL.sql
select 1 from dual;

$ ./SQL.sh
Hello

	 1
----------
	 1

("hangs" - pressing Control-D, or typing exit would "fix" this!)

Code:
$ cat SQL.sql
select 1 from dual;
exit;

$ ./SQL.sh
Hello

	 1
----------
	 1

Good bye

This User Gave Thanks to Scott For This Post:
# 4  
Old 06-15-2011
Yes, I remember the "exit" being an issue with this once before. I'll give it a try and let you know.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Pass value from sqlplus to shell on AIX

hello friend good morning I have a problem, how can I take the value that the PROCEDURE returns to me in the variable "CodError", when the connection to the bbdd is closed I lose the value and I need it in the shell #AIX cat <<EOF | sqlplus -s ${ORA_LOGIN}/${ORA_PASSWORD} > $logftmp set... (6 Replies)
Discussion started by: tricampeon81
6 Replies

2. Shell Programming and Scripting

How to pass Variable from shell script to select query for SqlPlus?

echo "set echo off"; echo "set feedback off"; echo "set linesize 4000"; echo " set pagesize 0"; echo " set sqlprompt ''"; echo " set trimspool on"; Select statement is mentioned below echo "select res.ti_book_no from disney_ticket_history res where res.ti_status =${STATUS} and... (7 Replies)
Discussion started by: aroragaurav.84
7 Replies

3. Shell Programming and Scripting

Shell Script passing parameters to sqlplus code

Hello All, I am interested in finding out a way to pass parameters that are entered at the prompt from HP unix and passed to SQLPlus code with a Shell Script. Is this possible? Thanks (4 Replies)
Discussion started by: compprog11
4 Replies

4. Shell Programming and Scripting

pass shell parameters to awk does not work

Why does this work for myfile in `find . -name "R*VER" -mtime +1` do SHELLVAR=`grep ^err $myfile || echo "No error"` ECHO $SHELLVAR done and outputs No error err ->BIST Login Fail 3922 err No error err ->IR Remote Key 1 3310 err But... (2 Replies)
Discussion started by: alan
2 Replies

5. Shell Programming and Scripting

How to pass parameter from sqlplus(procedure completed) to your shell script

if then # mail -s "Import failed file does not exist" sanjay.jaiswal@xyz.com echo "FILE does not exist" exit 1 fi echo "FILE EXIST" size=-1 set $(du /export/home/oracle/nas/scott21.dmp.gz) while do echo "Inside the loop" size=$1 set $(du... (1 Reply)
Discussion started by: sanora600
1 Replies

6. Shell Programming and Scripting

To pass the .sql file as a paramter to sqlplus through shell programming

Hi, Currently i have a .sql file 1.sql. I need to pass that as a parameter through a shell script to the sqlplus inside the same shell script. How I should I do.can anyone help me pls. I have an req where I need to send the .sql file and the place where the script has to create a .csv... (9 Replies)
Discussion started by: Hemamalini
9 Replies

7. Shell Programming and Scripting

help me in sending parameters from sqlplus script to unix shell script

Can anybody help me out in sending parameters from sql*plus script to unix shell script without using flat files.. Initially in a shell script i will call sql*plus and after getting some value from some tables, i want that variable value in unix shell script. How can i do this? Please tell me... (2 Replies)
Discussion started by: Hara
2 Replies

8. UNIX for Dummies Questions & Answers

How to pass two or more parameters to the main in shell script

Hey Guys from the below script what I understood is we are sending the the first parameter as input to the main (){} file main > $LOGFILE 2>&1 but can we send two or three parameter as input to this main file as main > $LOGFILE 2>&1 2>&2 like this Can any one plz help I need to writ a... (0 Replies)
Discussion started by: pinky
0 Replies

9. Shell Programming and Scripting

How to pass Shell variables to sqlplus use them as parameters

Hi, I am trying to pass some of the variables in my shell scripts to the sqlplus call and use them as parameters. For example, I would like to replace the 'SAS', and '20050612' with $var1 and $var2, respectively, how can I do that? --------------------------------------------------------... (1 Reply)
Discussion started by: Jtrinh
1 Replies

10. Shell Programming and Scripting

passing parameters from a shell script to sqlplus

Hi , I want to pass parameters from a shell script to a sql script and use the parameter in the sql query ..and then I want to spool a particular select query on to my unix box... for 4 different locations by writing only one sql script Right now no file is generated on the unix box...it is a... (2 Replies)
Discussion started by: phani
2 Replies
Login or Register to Ask a Question