Executing shell script through PL/SQL
Hi,
I need some help regarding execution of shell script through Oracle PL/SQL.
I have a shell script present in /abc/xyz folder with name search.sh , Through a PL/SQL procedure I am creating a file to store the report data.
I want to execute /abc/xyz/search.sh from the PL/SQL procedure to delete all files created before 3 mins .
1. At first I took Java route and got following permissions granted for RECON user.
GRANT USER SYS java.io.FilePermission <<ALL FILES>> execute ENABLED 351
GRANT USER SYS java.lang.RuntimePermission readFileDescriptor * ENABLED 350
GRANT USER SYS java.lang.RuntimePermission writeFileDescriptor * ENABLED 349
2. Then I created a simple java class for execution of OS command as below
CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "OSCommand" AS
import java.io.*;
import java.util.*;
public class OSCommand{
public static String Run(String Command){
try{
Process proc = Runtime.getRuntime().exec(Command);
int ext=proc.waitFor();
return ("0");
catch (Exception e){
System.out.println("Error running command: " + Command +
"\n" + e.getMessage());
return(e.getMessage());
3. And a wrapper function as below to use this class
create or replace
FUNCTION OSCommand_Run(Command IN STRING)
RETURN VARCHAR2 IS
LANGUAGE JAVA
NAME 'OSCommand.Run(java.lang.String) return int';
4. In my PL/SQL proceedure I am using following code to execute the command
v_Return := OSCommand_Run('/abc/xyz/search.sh');
to execute the shell script.
Proceedure executes without any error and generates a new csv file with report data , however shell script does not get executed and hence all csv files created earlier remain as it is in the folder.
Please help.
Sven W. wrote:
What happens if you remove the catch exception block from your java command?
I asume you still might have a permission issue. But it could be hidden from you, because of the exception is catched and printed into nirvana.Executed the wrapper function OSCOMMAND_RUN as below
DECLARE
v_Return VARCHAR2(2000);
BEGIN
v_Return := OSCOMMAND_RUN('/recon/html/invoice/search.sh' );
DBMS_OUTPUT.PUT_LINE('v_Return = ' || v_Return);
END;
And following is the result
v_Return = 0
Process exited.
In case of exception it would had printed the exception.
One more thing I noticed, even though I have taken following permissions
GRANT RECON SYS java.io.FilePermission /abc/* execute ENABLED 347
GRANT RECON SYS java.io.FilePermission /abc/xyz/* execute ENABLED 351
GRANT RECON SYS java.io.FilePermission <<ALL FILES>> execute ENABLED 352
GRANT RECON SYS java.lang.RuntimePermission readFileDescriptor * ENABLED 350
GRANT RECON SYS java.lang.RuntimePermission writeFileDescriptor * ENABLED 349
When I create a new search.sh in /abc dir I get following error
v_Return = the Permission (java.io.FilePermission /abc/search.sh execute) has not been granted to RECON. The PL/SQL to grant this is dbms_java.grant_permission( 'RECON', 'SYS:java.io.FilePermission', '/abc/search.sh', 'execute' )
Edited by: 960702 on Sep 25, 2012 10:34 AM
Similar Messages
-
Executing Shell Scripts through PL-SQL
Hi All,
I am trying to execute a shell script from PL-SQL but I am not getting it right .
the code i used is as follows
----JAVA CLASS ---
CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Host" AS
import java.io.*;
public class Host {
public static void executeCommand(String command) {
try {
String[] finalCommand;
if (isWindows()) {
finalCommand = new String[4];
// Use the appropriate path for your windows version.
finalCommand[0] = "C:\\windows\\system32\\cmd.exe"; // Windows XP/2003
//finalCommand[0] = "C:\\winnt\\system32\\cmd.exe"; // Windows NT/2000
finalCommand[1] = "/y";
finalCommand[2] = "/c";
finalCommand[3] = command;
else {
finalCommand = new String[3];
finalCommand[0] = "/bin/sh";
finalCommand[1] = "-c";
finalCommand[2] = command;
final Process pr = Runtime.getRuntime().exec(finalCommand);
pr.waitFor();
new Thread(new Runnable(){
public void run() {
BufferedReader br_in = null;
try {
br_in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String buff = null;
while ((buff = br_in.readLine()) != null) {
System.out.println("Process out :" + buff);
try {Thread.sleep(100); } catch(Exception e) {}
br_in.close();
catch (IOException ioe) {
System.out.println("Exception caught printing process output.");
ioe.printStackTrace();
finally {
try {
br_in.close();
} catch (Exception ex) {}
}).start();
new Thread(new Runnable(){
public void run() {
BufferedReader br_err = null;
try {
br_err = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
String buff = null;
while ((buff = br_err.readLine()) != null) {
System.out.println("Process err :" + buff);
try {Thread.sleep(100); } catch(Exception e) {}
br_err.close();
catch (IOException ioe) {
System.out.println("Exception caught printing process error.");
ioe.printStackTrace();
finally {
try {
br_err.close();
} catch (Exception ex) {}
}).start();
catch (Exception ex) {
System.out.println(ex.getLocalizedMessage());
public static boolean isWindows() {
if (System.getProperty("os.name").toLowerCase().indexOf("windows") != -1)
return true;
else
return false;
---PROCEDURE TO BE EXECUTED WHICH USES THE ABOVE JAVA CLASS IS ----
CREATE OR REPLACE PROCEDURE Host_Command (p_command IN VARCHAR2)
AS LANGUAGE JAVA
NAME 'Host.executeCommand (java.lang.String)';
--- THE PERMISSIONS ---
call dbms_java.grant_permission('SYSTEM', 'SYS:java.io.FilePermission', '<<ALL FILES>>', 'read ,write, execute, delete');
call dbms_java.grant_permission('SYSTEM', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');
call dbms_java.grant_permission('SYSTEM', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');
--- THE SHELL SCRIPT IS -----
#!/bin/sh
# This script removes the carriage returns from the Files having .DAT1 extensions in the /test/ Directory
# and the sends the single line stream to the new file with the use of 'gawk' command
# so finaly the files with same primary name but different secondary name are created
# e.g. file 'test.DAT1' is onverted to 'test.DAT'
# LOOP on /test/ DIRECTORY FOR SEARCHING FILES HAVING EXTENSION *.DAT1
for file_name in `ls /test/*.DAT1`
do
new_file_name=`echo $file_name | sed 's/DAT1/DAT/'`
# SEND THE CONTAINTS OF SELECTED FILE IN LOOP AS A CONTINUOUS STREAM TO NEW FILE NAME USING 'gawk' COMMAND
gawk 'BEGIN { ORS = "''" } { print $0 }' $file_name >> $new_file_name
# ABOVE LINE WILL CREATE A NEW FILE WITH SAME PRIMARY NAME BUT .DAT AS SECONDARY NAME(EXTENSION)
# REMOVE THE PRIOR FILE(s) AFTER SUCCESSFUL CALL TO 'gawk'
# $? returns 0 if the call to gawk command is succesfull
if test 0 = "$?"
then
rm -f $file_name
fi
done
# END LOOP ON /test/ DIRECTORY
---THE CALL TO THE PROCEDURE --
SQL>CALL DBMS_JAVA.SET_OUTPUT(1000000);
SQL>SET SERVEROUTPUT ON SIZE 1000000
SQL>exec host('/root/sh ecs_script.sh'); -----------------------------------------------1
now, the statement 1 is the path of the Shell Script ecs_script.sh
which uses gawk command and does some operations on some file..
but when i give the call in Statement 1 its giving error like
/bin/sh is not a directory
so i am not getting wHat should I do so that my script "ecs_script.sh" gets executed..
Please Help.The Java proc says:
> finalCommand[0] = "/bin/sh";
finalCommand[1] = "-c";
finalCommand[2] = command;
You call it as follows:
SQL>exec host('/root/sh ecs_script.sh');
The final command will be:
/bin/sh -c /root/sh ecs_script.sh
Is this what you intended? -
Execute Shell Script through Demantra Workflow
Hi All ,
Can we execute shell script from Demantra Workflow ?
If yes where should we place the shell script file and wat should be the commandline command in the step .
We have the Demantra installed on a windows server and the workflow manager is on a linux server .
the batch file on the windows server can be executed through the secure shell from the linux server .
I am trying to achieve the same through thr demantra workflow
Appreciate any input on the same .
Thanks and regards
SuzyHi,
Shell script is not supported till Demantra 7.2.0.2 WF.
I have checked with Oracle team also and reply I got below for your reference:
QUESTION
*=========*
As per your details, shall we conclude like this:
*"only *.bat and *.exe files can be used in workflow. Demantra standard functionality doe*
*s not support shell script in workflow"*
ANSWER
*=======*
Hi ,
The Demantra standard functionality 7.2.0.2 does support shell script in workflow.
Thanks,
Asya
Please review the note#468071.1-Unable to Run EBS Workflows that Call EngineManager.exe in
You will find this note is referring to the Enhancement Request Bug 6644455-- ANALYTICAL ENGINE
NOT AVAILABLE ON UNIX/LINUX
But the enhancement bug exist and I hope it is fixed in Demantra 7.3.
Tks
MJ -
Need Help on Executing Shell Scripts through PL-SLQ
Hi All,
I am trying to execute a shell script from PL-SQL but I am not getting it right .
the code i used is as follows
----JAVA CLASS ---
CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Host" AS
import java.io.*;
public class Host {
public static void executeCommand(String command) {
try {
String[] finalCommand;
if (isWindows()) {
finalCommand = new String[4];
// Use the appropriate path for your windows version.
finalCommand[0] = "C:\\windows\\system32\\cmd.exe"; // Windows XP/2003
//finalCommand[0] = "C:\\winnt\\system32\\cmd.exe"; // Windows NT/2000
finalCommand[1] = "/y";
finalCommand[2] = "/c";
finalCommand[3] = command;
else {
finalCommand = new String[3];
finalCommand[0] = "/bin/sh";
finalCommand[1] = "-c";
finalCommand[2] = command;
final Process pr = Runtime.getRuntime().exec(finalCommand);
pr.waitFor();
new Thread(new Runnable(){
public void run() {
BufferedReader br_in = null;
try {
br_in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String buff = null;
while ((buff = br_in.readLine()) != null) {
System.out.println("Process out :" + buff);
try {Thread.sleep(100); } catch(Exception e) {}
br_in.close();
catch (IOException ioe) {
System.out.println("Exception caught printing process output.");
ioe.printStackTrace();
finally {
try {
br_in.close();
} catch (Exception ex) {}
}).start();
new Thread(new Runnable(){
public void run() {
BufferedReader br_err = null;
try {
br_err = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
String buff = null;
while ((buff = br_err.readLine()) != null) {
System.out.println("Process err :" + buff);
try {Thread.sleep(100); } catch(Exception e) {}
br_err.close();
catch (IOException ioe) {
System.out.println("Exception caught printing process error.");
ioe.printStackTrace();
finally {
try {
br_err.close();
} catch (Exception ex) {}
}).start();
catch (Exception ex) {
System.out.println(ex.getLocalizedMessage());
public static boolean isWindows() {
if (System.getProperty("os.name").toLowerCase().indexOf("windows") != -1)
return true;
else
return false;
---PROCEDURE TO BE EXECUTED WHICH USES THE ABOVE JAVA CLASS IS ----
CREATE OR REPLACE PROCEDURE Host_Command (p_command IN VARCHAR2)
AS LANGUAGE JAVA
NAME 'Host.executeCommand (java.lang.String)';
--- THE PERMISSIONS ---
call dbms_java.grant_permission('SYSTEM', 'SYS:java.io.FilePermission', '<<ALL FILES>>', 'read ,write, execute, delete');
call dbms_java.grant_permission('SYSTEM', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');
call dbms_java.grant_permission('SYSTEM', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');
--- THE SHELL SCRIPT IS -----
#!/bin/sh
# This script removes the carriage returns from the Files having .DAT1 extensions in the /test/ Directory
# and the sends the single line stream to the new file with the use of 'gawk' command
# so finaly the files with same primary name but different secondary name are created
# e.g. file 'test.DAT1' is onverted to 'test.DAT'
# LOOP on /test/ DIRECTORY FOR SEARCHING FILES HAVING EXTENSION *.DAT1
for file_name in `ls /test/*.DAT1`
do
new_file_name=`echo $file_name | sed 's/DAT1/DAT/'`
# SEND THE CONTAINTS OF SELECTED FILE IN LOOP AS A CONTINUOUS STREAM TO NEW FILE NAME USING 'gawk' COMMAND
gawk 'BEGIN { ORS = "''" } { print $0 }' $file_name >> $new_file_name
# ABOVE LINE WILL CREATE A NEW FILE WITH SAME PRIMARY NAME BUT .DAT AS SECONDARY NAME(EXTENSION)
# REMOVE THE PRIOR FILE(s) AFTER SUCCESSFUL CALL TO 'gawk'
# $? returns 0 if the call to gawk command is succesfull
if test 0 = "$?"
then
rm -f $file_name
fi
done
# END LOOP ON /test/ DIRECTORY
---THE CALL TO THE PROCEDURE --
SQL>CALL DBMS_JAVA.SET_OUTPUT(1000000);
SQL>SET SERVEROUTPUT ON SIZE 1000000
SQL>exec host('/root/sh ecs_script.sh'); -----------------------------------------------1
now, the statement 1 is the path of the Shell Script ecs_script.sh
which uses gawk command and does some operations on some file..
but when i give the call in Statement 1 its giving error like
/bin/sh is not a directory
so i am not getting wHat should I do so that my script "ecs_script.sh" gets executed..
Please Help.@ Bhagat & Michaels
Dear Friends,
I changed my shell name as per ur suggestions
and recompiled the Java class source with
finalCommand[0] = "/bin/bash"; instead of finalCommand[0] = "/bin/sh";
and then recompiled the host procedure
executed the host procedure as per ur suggestion as follows (with out put)
SQL> exec host('/bin/bash ecs_script.sh')
PL/SQL procedure successfully completed.
bt, bt, bt, it still did not do any operations defined in the "ecs_script.sh"
in fact the script did nt executed.......
pls help , I am loosing my time..
regards. -
Hello All,
I have been using some well known Java Class and Procedures to execute shell scripts from PL-SQL.
The different environments I was using before were
1)
Operating System (Server) AIX version 5
Oerating System(Client) Microsoft Windows XP Service Pack 2
Oracle Database Version Oracle Database 10g Enterprise Edition Release
10.2.0.1.0
2)
Operating System (Server) Red Hat Linux 3.4.5-2
Oerating System(Client) Microsoft Windows XP Service Pack 2
Oracle Database Version Oracle Database 10g Enterprise Edition Release
10.2.0.1.0
But suddenly I had to drop and recreate the Databases on 1st (AIX) environment
and
reinstall the Operating System (Server) Red Hat 3.4.5-2 on IInd environment stated above (which obviously means the reinstallation of Oracle Database there!)
Now the shell script(through PL-SQL)is executing smoothly for the IInd (Linux) environment[b] but not executing for the Ist (AIX) environment
and I am not getting how to solve the problem.
I have given all the permissions to users, shell scripts and all as they were before.
Can you please help?
Regards,
Abhijit.Hello All,
I have been using some well known Java Class and Procedures to execute shell scripts from PL-SQL.
The different environments I was using before were
1)
Operating System (Server) AIX version 5
Oerating System(Client) Microsoft Windows XP Service Pack 2
Oracle Database Version Oracle Database 10g Enterprise Edition Release
10.2.0.1.0
2)
Operating System (Server) Red Hat Linux 3.4.5-2
Oerating System(Client) Microsoft Windows XP Service Pack 2
Oracle Database Version Oracle Database 10g Enterprise Edition Release
10.2.0.1.0
But suddenly I had to drop and recreate the Databases on 1st (AIX) environment
and
reinstall the Operating System (Server) Red Hat 3.4.5-2 on IInd environment stated above (which obviously means the reinstallation of Oracle Database there!)
Now the shell script(through PL-SQL)is executing smoothly for the IInd (Linux) environment[b] but not executing for the Ist (AIX) environment
and I am not getting how to solve the problem.
I have given all the permissions to users, shell scripts and all as they were before.
Can you please help?
Regards,
Abhijit. -
How we can call or execute a SHELL script through Oracle forms or Reports
How we can call or execute a SHELL script through Oracle forms or Reports.Its urgent.......
Use HOST command.
-
ABAP program to execute shell script !
Hi Friends,
I have created some shell scripts and need to be executed through ABAP prog in order to automate some process. can any one tell me how to execute these scripts through ABAP program? i know that we have to setup those scripts through SM69 but i dont have clear idea about this.can some one tell me step by step how to do this. ur help will be awarded in terms of points.
ThanksDefine the scripts as commands in SM69. Test them in SM69/SM49 to see if they work.
Next, go to SE37, run FM SXPG_COMMAND_EXECUTE, and specify your command there. Does it work?
If yes, you can just code a 'CALL FUNCTION' to this FM in your ABAP program, and you are ready to invoke your script from your ABAP.
For a list of functions that work with commands (defined in SM69), do a drop-down on SXPG_COMMAND* in SE37.
A sample code may look like this
concatenate zsys_id z_infile z_extfile into parm
separated by space.
*C_FTP_COMMAND is a script defined in SM49
CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
EXPORTING
COMMANDNAME = C_FTP_COMMAND
ADDITIONAL_PARAMETERS = parm
OPERATINGSYSTEM = SY-OPSYS
TABLES
EXEC_PROTOCOL = PROT
EXCEPTIONS
NO_PERMISSION = 1
COMMAND_NOT_FOUND = 2
PARAMETERS_TOO_LONG = 3
SECURITY_RISK = 4
WRONG_CHECK_CALL_INTERFACE = 5
PROGRAM_START_ERROR = 6
PROGRAM_TERMINATION_ERROR = 7
X_ERROR = 8
PARAMETER_EXPECTED = 9
TOO_MANY_PARAMETERS = 10
ILLEGAL_COMMAND = 11
WRONG_ASYNCHRONOUS_PARAMETERS = 12
CANT_ENQ_TBTCO_ENTRY = 13
JOBCOUNT_GENERATION_ERROR = 14
OTHERS = 15.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
else.
write: /, 'FTP Function module executed with no errors.'.
ENDIF. -
Running Shell scripts through JAva
Hi,
I tried to execute a Shell script through a Java program.
The code I used is as below:
import java.lang.*;
import java.io.*;
public class sys {
public static void main(String[] args) {
Runtime rt = Runtime.getRuntime();
String[] callAndArgs = { "chgpasswd" };
try {
Process child = rt.exec(callAndArgs);
child.waitFor();
System.out.println("Process exit code is: " + child.exitValue());
catch(IOException e) {
System.err.println( "IOException starting process!");
catch(InterruptedException e) {
System.err.println( "Interrupted waiting for process!");
The "chgpasswd" shell script calls the "passwd" command of Unix.
It threw out an IO exception.
Then I gave the parameter as "./chgpasswd". It now gave an exit value of 255.
The "chgpasswd" script exists in the same directory as the .class file.
I checkd up the exit code reference...it says exit value of 255 could mean as exit code out of range........an exit code > 255....which unfortunately has no documentation, I guess.
Can you help ?This is on a Unix platform, correct? Assuming so...
If I remember correctly, exit codes can be greater than 255. To get the real exit code equates to something like: exitcode & 512 to obtain the real exit code.
Make sure "chgpasswd" shell script has the execute permissions set. Additionally, make sure that the first line of the script (the magic line) has the appropriate shell/interpreter to execute specified. For example, if "chgpasswd" were a Bourne (sh) script, the first like would be:
#!/bin/shFor perl, it may be something like:
#!/usr/bin/perlIt needs to be the absolute path to the shell/interpreter is the point. -
How to pass arguments to a Unix shell script from PL/SQL?
We want to run a Linux shell script from PL/SQL (10g). This is our code to run the script only and it works fine.
dbms_scheduler.create_job
job_name=>'RUN_LINUX_SCRIPT_' || v_job_name,
job_type=>'EXECUTABLE',
job_action=>'/vol0/FileLoadDir/Bank/DATA_FILES/spell_check.sh',
enabled=>TRUE,
auto_drop=>FALSE
);Now we have a requirement to pass 2 arguments to the .sh file. In the .sh file the 2 arguments are defined as $1 and $2.
I used this method.
dbms_scheduler.create_job
job_name=>'RUN_LINUX_SCRIPT_' || v_job_name,
job_type=>'EXECUTABLE',
job_action=>'/vol0/FileLoadDir/Bank/DATA_FILES/spell_check2.sh',
--job_action=>'/vol0/FileLoadDir/Bank/DATA_FILES/spell_check2.sh /vol0/FileLoadDir/Bank/DATA_FILES/ebill2.fmt_form_strings_.txt /vol0/FileLoadDir/Bank/DATA_FILES/abcdefghij.txt',
--job_action=>'#!/bin/bash spell /vol0/FileLoadDir/Bank/DATA_FILES/ebill2.fmt_form_strings_.txt > /vol0/FileLoadDir/Bank/DATA_FILES/abcde.txt',
number_of_arguments => 2,
enabled=>FALSE,
auto_drop=>FALSE,
comments => 'Testing by Channa'
DBMS_SCHEDULER.SET_JOB_ARGUMENT_VALUE (
job_name => 'RUN_LINUX_SCRIPT_' || v_job_name,
argument_position => 1,
argument_value => '/vol0/FileLoadDir/Bank/DATA_FILES/ebill2.fmt_form_strings_.txt');
DBMS_SCHEDULER.SET_JOB_ARGUMENT_VALUE (
job_name => 'RUN_LINUX_SCRIPT_' || v_job_name,
argument_position => 2,
argument_value => '/vol0/FileLoadDir/Bank/DATA_FILES/abcdefghij.txt');
DBMS_SCHEDULER.enable (name => 'RUN_LINUX_SCRIPT_' || v_job_name);But I get an error saying:
STANDARD_ERROR="/vol0/FileLoadDir/Bank/DATA_FILES/spell_check2.sh: line 4: read: `/vol0/FileLoadDir/Bank/DATA_FILES/ebill2.fmt_form_strings_.txt': not a valid identifier
/vol0/FileLoadDir/Bank/DATA_FILES/spell_check2"Check this post:
pass parameter from PL/SQL to Unix "as is" -
Can any one tell me how can i call a shell script from pl/sql
i like to call shell script from pl/sql procedure.
can any one suggest how can i do thisHave you not mastered in asking the same kind of question ?
First do write a script...
no one will spoon feed you.
How can i call a shell script from procedure
How to call Shell Script from pl/sql block
-Sk -
Error to execute the script through command prompt
I tried to execute the script through command prompt. I got some following error. Could you please advice me how to rectify this.
cscript D:\JS\Test.js
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
D:\JS\Test.js(1, 1) Microsoft JScript runtime error: 'app' is undefined.
Thanks,
PrabudassI haven't use CS for quite some time and file associations may not work with the command prompt.
You can try using Windows Explorer to browse to a .js file then right click on that file. From the popup menu choose Open With. Even if you see Photoshop in the file list choose Browse at the bottom. Browse to Photoshop and make sure to check 'Always use selected program...'
If that doesn't work you will need to create an action that runs your script and make a droplet from that action. You can then use the droplet in the command prompt. You may also need to create a 'dummy' image file to launch the droplet with if you script doesn't require an open document at startup. See http://www.ps-scripts.com/bb/viewtopic.php?t=967 -
How to prepare for Converting UNIX shell scripts to PL/SQL
Hi All
I was said, that i may have to convert a lot of unix shell script to PL/SQL, what are the concepts i need to know to do it efficently,
what are the options PL/SQL is having to best do that.
I know the question is little unclear, but I too dont have much inputs about that i'm sorry for that, just its a question of how
to prepare myself to do it the best way. What are the concepts i have to be familiar with.
Many Thanks
MJJust how much work is involved, is hard to say. Many years ago I also wrote (more than once) a complete ETL system using a combination of shell scripts, SQL*Plus and PL/SQL.
If the PL/SQL code is fairly clean, uses bind variables and not substitution variables, then it should be relatively easy to convert that PL/SQL code in the script to a formal stored procedure in the database.
There is however bits and pieces that will be difficult to move into the PL/SQL layer as it requires new software - like for example FTP'ing a file from the production server to the ETL server. This can be done using external o/s calls from within PL/SQL. Or, you can install a FTP API library in PL/SQL and FTP that file directly into a CLOB and parse and process the CLOB.
Think of Oracle as an o/s in its own right. In Oracle we have a mail client, a web browser, IPC methods like pipes and messages queues, cron, file systems, web servers and services, etc. And PL/SQL is the "shell scripting" (times a thousand) language of this Oracle o/s .
In some cases you will find it fairly easy to map a Unix o/s feature or command to one in Oracle. For example, a Unix wget to fetch a HTML CSV file can easily be replaced in Oracle using a UTL_HTTP call.
On the other hand, techniques used in Unix like creating a pipe to process data, grep for certain stuff and awk certain tokens for sed to process further... in Oracle this will look and work a lot different and use SQL. -
Invoke shell script thru pl/sql
Hi,
Is it possible to invoke a shell script thru a stored procedure? If possible how do we go about?
For example,
We have an application which has the following architecture:
Front End : Java (web enabled)
Middle Tier : Java web server 2.0
Back End : Oracle 8.1.6 on Solaris 2.7.
Our application needs sql loader to be invoked thru the web. For that there are two approaches.
1. Call the SQL Loader from front end itself. For this we need to have signed servlets etc., This seems quite complex because our back end and web server resides in two different solaris servers.
2. Call a stored procedure from front end which in turn calls the shell scripts which can in turn invoke sql loader etc.,
Do you have better solutions? Any suggestion will be deeply appreciated.
Thanks,
Raghu.Dear Raghu,
As per my experience calling external procedures from oracle may cause some moderate-to-severe problems. I suggest an alternative solution which is the following:
1. Your PL/SQL program calls a C cartridge using ICX. The way it works is you call utl_http.request() or utl_http.request_pieces() if the amount of data to be passed back exceeds 2000 characters.
2. The C cartridge is basically "Hello WORLD" from Oracle examples. The only change is that you substitute the WRB_printf("Hello World") with popen("script.ksh",...)
3. This way the C cartridge calls your shell script.
--PL/SQL
BEGIN
utl_http.request(...); --> calls C
END;
/* C cartridge
popen("script.ksh",...) /* --> Calls shell */
#Shell script1.ksh --> calls sqlldr
sqlldr ...
P.S. You gotta have at least Oracle 7.3.4 with the OAS at least 3.02 -
Shell script to call sql script
Hi All,
I have a application server and want to make a shell script to call sql script.
Please let me know how to do the same.
Regards
KumarWhat is the platform you are using and you can give the path of the sql script in your shell script as follows
1.)first create .sql file...let it is table.sql and has the contents ...
create table test(x1 varchar2(20),x2 number(4),x3 date)
exit;
(2.) write a shell script...like table.sh in vi editor
Here login is scott/tiger@sid, or apps/apps@sid or whatever you know valid schema
echo enter the login
read login
sqlplus -s $login @table
(3.)run the script
$ sh table.sh
it will create the table in your particular schema -
Running Unix Shell scripts through Java
How to run Unix shell scripts through Java program ?
Use:
Process p = Runtime.getRuntime().exec("sh script.sh");Then you can use:
p.getOutputStream and read the output of your program.
Maybe you are looking for
-
F110 Grouping all vendors on one payment
Hello all, I am trying to make a payment via F110 that's pays 3 vendors invoices from the same company code, same house bank, same Payment method. Now as F110 works, but making 3 payment documents, one document for each vendor : Doc 1 Debit Vendor 1
-
Recently when I pull up a multi-page document from an internet site, I can only see the first page. I can't scroll through it. When I try to print, I get a big blue questionmark. What's the solution to this, please?
-
Hi! I have a Home Hub and connect wirelessly via my laptop. I now would like to connect my freesat TV to acess iplayer with an ethernet cable as well but although the cable is plugged in fine it is not registering any connection? Is it possible to ha
-
I've many alarms with more than one signature with destination ip address 0.0.0.0 source and destination port 0 how can I intend these messages?
-
Exporting video downloaded from itunes
I've downloaded a couple shows from the itunes store and wanted to export them using QT Pro to another format. But when i open the movie the export command is greyed out and cannot be selected. I've tried this with a few different itunes video downlo