Need help with ksh script that uses sqlplus, called from PHP


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help with ksh script that uses sqlplus, called from PHP
# 1  
Old 02-23-2006
Need help with ksh script that uses sqlplus, called from PHP

I have a ksh script that connects to sqlplus and dumps the query results into a file. The script works file when I run it from the command line, however, when I call it from PHP using system(), exec(), or shell_exec() commands, the script doesn't seem to run the query. It will create the text file but nothing's in it. I've used 'whoami' to verify the user is the same as I'm logging in with. Any ideas? Any help would be much appreciated.

Jeff

Here's ksh script (actual sql replaced for brevity)
#!/bin/ksh

# Passed Parameters:
site=$1

# Output file name:
OUTPUT_FILE=results-${site}.txt

# initiate sqlplus with silent option
sqlplus -s usr/pwd <<!>${OUTPUT_FILE}
whenever sqlerror exit 2
set heading off
set pages 0
set linesize 195
set tab on
set feedback off
set verify off

select * from app_user
/
!

exit 0
# 2  
Old 02-23-2006
It's probably not running as an interactive shell so therefore, you need to obtain your Oracle environment variables explicitly.

Code:
#!/bin/ksh


export ORACLE_SID=$ORACLE_SID
ORAENV_ASK=NO
. /usr/local/bin/oraenv
ORAENV_ASK=


# Passed Parameters:
site=$1

# Output file name:
OUTPUT_FILE=results-${site}.txt

# initiate sqlplus with silent option
sqlplus -s usr/pwd <<!>${OUTPUT_FILE}
whenever sqlerror exit 2
set heading off
set pages 0
set linesize 195
set tab on
set feedback off
set verify off

select * from app_user
/
!

exit 0

# 3  
Old 02-27-2006
Thanks, that helped. However, I am now getting the following error:

ERROR:
ORA-01034: ORACLE not available
ORA-27123: unable to attach to shared memory segment
SVR4 Error: 13: Permission denied


Enter user-name: SP2-0306: Invalid option.
Usage: CONN[ECT] [logon] [AS {SYSDBA|SYSOPER}]
where <logon> ::= <username>[/<password>][@<connect_string>] | /
Enter user-name: SP2-0306: Invalid option.
Usage: CONN[ECT] [logon] [AS {SYSDBA|SYSOPER}]
where <logon> ::= <username>[/<password>][@<connect_string>] | /
SP2-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus


The user that the script is running as has permission to all of the Oracle directories. Anyone know what's wrong?

Thanks again for any help.
# 4  
Old 02-27-2006
What is happening is Oracle is trying to find a shared memory segment that matches your Oracle SID value. One of two things is happening, 1) you database is not online or 2) your $ORACLE_SID value is wrong. I'm sure that you know whether your database is running so have your DBA confirm your $ORACLE_SID value.
# 5  
Old 02-27-2006
Oh yeah, perhaps I should mention that this runs from the command line. It's when I call the script from a php page that it gets the error.
# 6  
Old 02-27-2006
Your php session still needs to have its parameters passed correctly. For grins, try addind your SID to the sqlplus command and see what happens:
Code:
sqlplus un/ps@db

# 7  
Old 02-27-2006
Quote:
Originally Posted by tmarikle
Your php session still needs to have its parameters passed correctly. For grins, try addind your SID to the sqlplus command and see what happens:
Code:
sqlplus un/ps@db

You sir, are the man! Where do I send the 6-pack? Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Weird issue - *ksh script not recognized when being called

HI Team - I'm running into a weird issue when trying to call a .ksh script. In my shell script, I'm using the following command to call my environment file: cd /hypbin/test ./_env.ksh But it's saying not found. Permissions are set correctly, shebang is set but I'm unsure why it's not... (5 Replies)
Discussion started by: SIMMS7400
5 Replies

2. Shell Programming and Scripting

Oracle/SQLPlus help - ksh Script calling .sql file not 'pausing' at ACCEPT, can't figure out why

Hi, I am trying to write a script that calls an Oracle SQL file who in turns call another SQL file. This same SQL file has to be run against the same database but using different username and password at each loop. The first SQL file is basically a connection test and it is supposed to sort... (2 Replies)
Discussion started by: newbie_01
2 Replies

3. Shell Programming and Scripting

Line break in sqlplus output through ksh script

Hi, I am new to shell script programming. I have written a ksh script to run the sql File placed in server directory and spool the output in destination directory. Below Command: $ORACLE_HOME/bin/sqlplus -s $ora_uid @$sqlfile_loc$testquery.sql > $opfiledirectory It is generating the output... (6 Replies)
Discussion started by: Sumit Arora
6 Replies

4. Shell Programming and Scripting

Shell Script (ksh) - SQLPlus query filter using a string variable

Using ksh, I am using SQLPlus to execute a query with a filter using a string variable. REPO_DB=DEV1 FOLDER_NM='U_nmalencia' FOLDER_CHECK=$(sqlplus -s /nolog <<EOF CONNECT user/pswd_select@${REPO_DB} set echo off heading off feedback off select subj_name from subject where... (5 Replies)
Discussion started by: nkm0brm
5 Replies

5. Solaris

sqlplus output from ksh.

Hi All, I have the below simple script. It runs just fine by itself when I manually invoke it. But once I put it in the crontab with entry: * * * * * /users/myuser/test.ksh >> /users/myuser/log/test.txt" It does NOT print the returned value ($REMAIN) from the DB!? The result in the... (3 Replies)
Discussion started by: steve701
3 Replies

6. Shell Programming and Scripting

Date command does not work in a KSH when called from Cron

Hi, I'm trying to execute a job on the last day of every month, for which i'm using the following code in my Korn shell script : if ]; then echo allowed only on last day of month. Today is `date +%d` >t.stm echo Tomorrow is `date +%d -d tomorrow` >s.stm exit 0 fi ... ....... (7 Replies)
Discussion started by: devilsadvocate
7 Replies

7. Shell Programming and Scripting

passing a variables value from the called script to calling script using ksh

How do i get the value of the variable from the called script(script2) to the calling script(script1) in ksh ? I've given portion of the script here to explain the problem. Portion of Script 1 ============= ----- ----- tmp=`a.ksh p1 p2 p3` if then # error processing fi -----... (10 Replies)
Discussion started by: rajarkumar
10 Replies

8. Shell Programming and Scripting

KSH Sqlplus problem

Hi, trying this =============================== Temp=`sqlplus -s user/passwd <<EOF WHENEVER SQLERROR EXIT 1 set serverout on set feedback off set heading off select nam from tabel1 where x=y; EOF` echo Temp>>$logfile ================================= The select statement is... (2 Replies)
Discussion started by: amitkr
2 Replies

9. Shell Programming and Scripting

How to acheive ALT+Enter of xls in Unix ksh/sqlplus

Hi, I am using sqlplus (called inside my ksh) to create a file which is mailed to the users as an xls. There is one DESCRIPTION column which is currently coming as wrapped, but, the users want a new line for each of the fields present in the desricription column. Below is an example - ... (11 Replies)
Discussion started by: Sree_2503
11 Replies

10. Shell Programming and Scripting

How to pass variable to SQLPLUS in a ksh script?

Hi, I am writing a ksh script which will use sqlplus to run a sql and pass 2 variables as the SQL request. In the ksh script, I have 2 variables which are $min_snap and $max_snap holding 2 different numbers. Inside the same script, I am using SQLPLUS to run an Oracle SQL script,... (6 Replies)
Discussion started by: rwunwla
6 Replies
Login or Register to Ask a Question