Sqlplus with shell_exec(); PHP command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sqlplus with shell_exec(); PHP command
# 1  
Old 05-14-2013
Sqlplus with shell_exec(); PHP command

Hi,

I need to run a PL/SQL Query from a distant oracle server in order to create spool files and send it to my own server, using a php script.

I firstly created a SH script called myscript.sh

Code:
#!/bin/bash

echo "This script is working"
sqlplus username/password//ip_address_distant_server:port/database @/var/www/mydirectory/myquery.sql parameter1 parameter2 parameter3

let's say that my PHP script is like :

Code:
shell_exec('sh var/www/mydirectory/myscript.sh');

Note that the sql file myquery.sql does contain spools that are supposed to send files to my own server...
When i run the script from the command line, it works. I use an normal user (not root) to make it run When i run it from the php page, it doesn't work. Apache use www-data to run it, so i made sure to include the www-data group to the script. Note that i tried running



Code:
shell_exec('ls -l');

and that it works like a charm! i also tried to run another sh script without sqlplus command, and it also work.


I'm suspecting a permission problem with the sqlplus command, because the only difference between both methods to run the script is the user running it. But i don't know how to change user permissions to a command, or a possible escape to make it work. I'm out of ideas i tried several things such as exec(); or system(); instead of shell_exec(); and changing chown and chmod to both sql / sh files


Any help would be really great, thanks Smilie
# 2  
Old 05-14-2013
Quote:
Originally Posted by cgstag
Code:
shell_exec('sh var/www/mydirectory/myscript.sh');

Perhaps the relative path is the problem.

Regards and welcome to the forum,
Alister
# 3  
Old 05-14-2013
Thank you Alister for the quick reply,

i don't think the relative path is the problem, because if i run the php script with shell_exec('sh /var/www/directory/script.sh');

with script.sh being :

Code:
#!/bin/bash

echo "This script is working"
sqlplus username/password//ip_address_distant_server:port/database @/var/www/mydirectory/myquery.sql parameter1 parameter2 parameter3

the echo command works, it will display "This script is working"
but the sql query does not run...it clearly shows that the php is not the problem, and i believe the problem is in the permission apache server user has to use sqlplus unix command.
I did not found enough information on the internet about this command (in oracle doc it really is looking for a needle in a haystack)...

thank you anyway !
# 4  
Old 05-14-2013
Ah, but that one does not have a relative path.

"var/path/to/whatever" means "start looking at the current directory", which may be the directory the PHP script is in.

"/var/path/to/whatever" means "Start looking in the root directory", making the current folder not matter.
# 5  
Old 05-14-2013
Absolute path calls and getting all the Oracle environment variables, PATH, LD_LIBRARY_PATH set right for sql*plus in the wrapper. Interactively, it inherits all yours.
# 6  
Old 05-15-2013
Quote:
Ah, but that one does not have a relative path.

"var/path/to/whatever" means "start looking at the current directory", which may be the directory the PHP script is in.

"/var/path/to/whatever" means "Start looking in the root directory", making the current folder not matter.
My mistake is in the first post where i posted var/www/mydirectory/myscript.sh instead of /var/www/mydirectory/myscript.sh. But basically, both ways would lead in the same directory as var is placed in the root...and anyway, as i said before, the bash script call is working just fine (the echo command works and prompt the text i want) its really just the sqlplus command not working.

Quote:
Absolute path calls and getting all the Oracle environment variables, PATH, LD_LIBRARY_PATH set right for sql*plus in the wrapper. Interactively, it inherits all yours
I am not sure i have understood what you told me, sorry ;
1) If you are telling me i need the absolute path, i think /var/www/mydirectory/mysqlquery.sql is absolute path... right ?
2) Is there any special code to include to get the oracle environment variables ?
# 7  
Old 05-16-2013
If you don't do so yourself, chances are your /etc/profile or your own ~/.profile or equivalent does so for you. Check the contents of those to see what they do, or just load /etc/profile itself like I suggested above.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX and Linux Applications

Problem on SQLplus command ""bash: sqlplus: command not found""

Hi all, i face an error related to my server ""it's running server"" when i use sqlplus command $ sqlplus bash: sqlplus: command not found the data base is up and running i just need to access the sqlplus to import the dump file as a daily backup. i already check the directory... (4 Replies)
Discussion started by: clerck
4 Replies

2. Shell Programming and Scripting

Sqlplus error - sqlplus -s <login/password@dbname> : No such file or directory

i am using bash shell Whenever i declare an array, and then using sqlplus, i am getting sqlplus error and return code 127. IFS="," declare -a Arr=($Variable1); SQLPLUS=sqlplus -s "${DBUSER}"/"${DBPASS}"@"${DBASE} echo "set head off ; " > ${SQLCMD} echo "set PAGESIZE 0 ;" >> ${SQLCMD}... (6 Replies)
Discussion started by: arghadeep adity
6 Replies

3. Shell Programming and Scripting

Can any one explain this sqlplus command?

Hi , i am new to unix i need a small clarification regarding this sqlplus -s $USER_NAME/$PASSWD@$ORA_SID<< EOF >> SQL_CONN_LOG.log In the above command what is the meaning of <<EOF>> Thanks, krishna. (2 Replies)
Discussion started by: rams_krishna
2 Replies

4. Web Development

php shell_exec

Hey guys i've recently been getting into php programming and i became thinking was it possible to create a php script that would allow you to run a terminal from the browser page? All i've pretty much got so far is: $var = $_GET; $output = php shell_exec($var); echo $output; ... (4 Replies)
Discussion started by: lordfirex
4 Replies

5. Ubuntu

sqlplus: command not found

I installed Oracle 10.2.1.0 in Ubuntu 10.10..my installation was well,i could even open isqlplus( http://ubuntu.ubuntu-domain:5560/isqlplus/workspace.uix ) and execute some queries..But,back in terminal when i try to login to sqlplus i am getting error (20 Replies)
Discussion started by: sandy0594
20 Replies

6. Shell Programming and Scripting

Help with PHP and shell_exec!!!

Hi, I've been working on a PHP script which is "supposed" to find an individuals weather based on their geolocation. This script uses "shell_exec". I have checked my syntax and it is correct, but there is still something missing; for when I call on the script using: <form action='/weather.php'... (15 Replies)
Discussion started by: o0110o
15 Replies

7. Shell Programming and Scripting

php shell_exec, exec command timeout

HI, Does anybody know if its possible to execute a command through exec, shell exec, system and if the program doesn't terminate in N seconds returns control to PHP ? reg, research3 ---------- Post updated 10-16-09 at 12:20 AM ---------- Previous update was 10-15-09 at 11:03 PM... (1 Reply)
Discussion started by: research3
1 Replies

8. HP-UX

sqlplus: command not found

hi, i need bash shell script run on the crontab(Unix tru64). i have write my shell. it's using sqlplus command and connect to oracle db. execute cron job when i have error messege: "sqlplus: command not found" have you any suggestion? (4 Replies)
Discussion started by: Tlg13team
4 Replies

9. Shell Programming and Scripting

Use sqlplus command

Can someone tell me how to execute sqlplus command. I`m Executing: sqlplus user/pasw @/report/output/new/PlatformOut_Cdrs.sql the error is: SQL*Plus: Release 9.2.0.5.0 - Production on Wed Aug 9 15:37:44 2006 Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved. ERROR:... (3 Replies)
Discussion started by: Nel
3 Replies

10. Shell Programming and Scripting

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... (7 Replies)
Discussion started by: j2owilson
7 Replies
Login or Register to Ask a Question

Featured Tech Videos