HOST command in SQLPlus
Hi everybody
I have a script with two HOST commands inside one script. The problem is that the second host command is executed just before the first host command terminates. Is there a way to make the second waits till the first ends ?
Thanks to all
hi.
I schedules my exports through crontab..
I create a script for each schema export job and submit them to cron and it automatically runs the export as I scheduled them.
Similar Messages
-
Host command from sqlplus based on a condition
I am on an Oracle 10.2.0.3.0 database running on sun solaris.
Am using my sqlplusw on my windows xp professional to do the below :
SQL> select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for Solaris: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
I have 4 variables declared in sqlplus for which I get my values from anonymous pl/sql blocks :
print db1_status;
DB1_STATUS
3
print db2_status;
DB2_STATUS
0
print db3_status;
DB3_STATUS
1
print db4_status;
DB4_STATUS
0
I needed some help with doing this :
Based on the values of each these variables, I wanted to invoke the host command to run stuff like
if db1_status = 3 then
host ...something
if db2_status = 0 then
host ...something
I am looking for a way to do this without creating an external procedure or java stored programs. Are there any?
ThanksNeed to use a batch file (.bat) to utilize SQL Plus while generating the SQL statements within the .bat file.
Example:
Inside SQL Plus
SQL> create table testme (name varchar2(255), value number(5));
Table created.
SQL> insert into testme(name, value) values ('db1_status', 3);
1 row created.
SQL> insert into testme(name, value) values ('db2_status', 0);
1 row created.Create a .bat file (Using test.bat)
test.bat
@echo off
echo select value from testme where name = 'db1_status';>temp.sql
echo exit >> temp.sql
sqlplus -S %2/%3@%1 @temp.sql > result.dat
for /f %%x in ('more result.dat') do set RESULT=%%x
if "%RESULT%" == "3" goto :DB1_STATUS_3
if not "%RESULT%" == "3" goto :DB1_STATUS_NOT_3
goto :EOF
:DB1_STATUS_3
echo db1_status = 3
**ENTER SYS COMMANDS HERE**
goto :EOF
:DB1_STATUS_NOT_3
echo db1_status != 3
**ENTER SYS COMMANDS HERE**
goto :EOF
echo select value from testme where name = 'db2_status';>temp.sql
echo exit >> temp.sql
sqlplus -S %2/%3@%1 @temp.sql > result.dat
for /f %%x in ('more result.dat') do set RESULT=%%x
if "%RESULT%" == "0" goto :DB2_STATUS_0
if not "%RESULT%" == "0" goto :DB2_STATUS_NOT_0
goto :EOF
:DB2_STATUS_0
echo db2_status = 0
**ENTER SYS COMMANDS HERE**
goto :EOF
:DB2_STATUS_NOT_0
echo db2_status != 0
**ENTER SYS COMMANDS HERE**
goto :EOF
:EOF
del temp.sql
del result.dat
@echo onAs you can see, this is a simple if/then which takes the value from a dynamically created SQL file (temp.sql) and uses it do determine the next system commands to execute.
Hope this is what ya needed.
-Tim -
SQLPLUS HOST Command Not Supported
Hi,
I am facing strange problem. I have lots of scripts where I have used the HOST command from within SQLPLUS.
Now, on Windows Server 3000 Standard Edition, Version 5.2, I find that both HOST and its equivalent $, both are not supported when used with SQLPLUS on Oracle 10g Enterprise Edition.
Please HELP, and suggest some alternative.
PrashantThere is no such thing as Windows Server 3000. The latest product appears to be Windows Server 2008.
I'm not sure what the version of the Oracle database has to do with it. This is about SQL*Plus and you still haven't told us what version of that you are using. For example:
SQL*Plus: Release 11.1.0.6.0 - Production on Sat Dec 6 15:56:12 2008
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> host cd
y:\sql
SQL>This is sqlplus.exe (never sqlplusw.exe) version 11.1.0.6.0 on Windows XP Pro 2002 SP3. It's not the best example because SQL*Plus and the database are at the same version - they are often different. For example:
/Users/williamr: sqlplus william/x@//vm.starbase.local:1521/eleven
SQL*Plus: Release 10.1.0.3.0 - Production on Sat Dec 6 16:01:21 2008
Copyright (c) 1982, 2004, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> ho uname -a
Darwin starbase-2.local 8.11.1 Darwin Kernel Version 8.11.1: Wed Oct 10 18:23:28 PDT 2007; root:xnu-792.25.20~1/RELEASE_I386 i386 i386
SQL> I've never known the host command not work, but perhaps someone with the same setup as you can confirm they don't have the same problem. I'm also a bit puzzled by the error message "Command not success." That doesn't sound like an Oracle command - apart from being vague and ungrammatical it doesn't start with the standard "SP2-nnnn" prefix, for example:
SQL> x
SP2-0042: unknown command "x" - rest of line ignored.Can you copy and paste the exact commands and results you get?
Edited by: William Robertson on Dec 6, 2008 4:04 PM -
HOST command not working in forms 10g
Hi,
I have migrated forms 6i to forms 10g, and having a requirement to open sqlplus prompt using a form menu. I have used the below command: -
"host('sqlplus '||user_name||'/'||pass||'@'||sid, no_screen);"
But I am not able to get the sqlplus window, and the main form is still in process for long time, till i bounce the server.
The forms are deployed on Oracle Applications Server 10g and i want to run it on server side.
Please help me with the problem.
Thanks,
AnkitThe deployment architecture is different between forms 10g and forms 6i.
In Forms 6i HOST built-in command will run on the client machine since you are running as client/server, but in WebForms (Forms10g) the HOST built-in command will run on the middle tier which is your application server machine.
In order to run hosts commands in WebForms you need to use webutil and use CLIENT_HOST in the webutil.
check the [Forms 10g R2 Demo|http://download.oracle.com/otndocs/demos/Forms_Demos_10gr2.zip] for sample codes of webutil.
You are using NO_SCREEN in your example, this will hide the window.
Tony
Edited by: Tony Garabedian on Nov 26, 2009 2:43 PM -
Call unix command in sqlplus script
Hello, I wanna to know how to call a unix command in the sqlplus script.
For exemple,
I've a sqlplus script to lauch a oracle report, after the report is generated, I wanne to replace the output file in an other directory.
So that, I have to call the unix command mv here in the sqlplus script
How can I do it?**
I completed my situation:
I don't have dbms_scheduler untility in my database.
Thanks a lot for your help
Edited by: user11930885 on 17 janv. 2010 14:53Yes, at the begining, I'll tried the unix shell by calling SQL.
I've the problem of passing the parameters through.
It seems to me
we can use
Host in the SQLPLUS to run the unix command.
but I've written it in my sqlplus script, it doesn't work. so I wanna to find an exemple how to use HOST in sqlplus script?
I would have loved to give you an example..but its not unix on my laptop.
But what i can tell you is...u should be doing otherway round.
Not calling Unix commands from SQL but calling SQL's form unix.
You got shell scripts for that.
Write a shell script. Login to SQL execute your code.
exit from sql and then move your file with MV. That's it.
Do post how far you get after trying this. -
How to run a script from Oracle Form (Beside using HOST command)
I would like to run a script from Forms 6.0. I know that we can actually issue this command :
host('plus80.exe' username/password@connect_string @c:\scriptname);
BUT, is there any other alternative ?Sqlplus is a different program, so one way or the other you have to leave Forms to run sqlplus. What is you objection against HOST?
You can also run sqlplus from the database, but again you need a stored java procedure to call sqlplus (sort of HOST command that runs in the database).
Francois' solution works if your script just has a query to run, but if you have specific sqlplus commands (spool etc.) forms_ddl is probably not a solution. -
Calling java host command in trigger/PLSQL
I created a java call to execute a linux host command that calls a shell script that will echo out a result. It is owned by SYS and has granted execute to SYSTEM. SYSTEM has a table that monitors accesses to the RDBMS. When a user logs on from a remote server vis sqlplus, this LOGON trigger write to the SYSTEM table (successfully). SYSTEM has a trigger that runs a linux command to execute a shell script that pulls the actual IP address from the remote system. I can run this call from a PLSQL block (outside the trigger) and get a response back like "user:101.101.101.111" but when I have the same user log on, the trigger fires - no errors or exceptions yet no rows are returned. Is there some restriction in a trigger versus just a plsql block call? The java code used is what I found on (http://www.oracle-base.com/articles/8i/ ... mPLSQL.php) and it works perfectly OUTSIDE the trigger but nothing is returned in the trigger firing steps. Any idea?
rdbms: 11.1.0.7, Redhat 4
I know the code works because I can write the host command output to a file. Later in the trigger I can open the file and can read the data that should have been returned in the java host call.FYI - here is the code from your site that I used:
DROP JAVA SOURCE SYS."Host";
CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED SYS."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("Cmd results: " + 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("Cmd Error: " + 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;
/ -
Use Host command in Oracle Database Trigger
I need to run Host command from a database trigger in order to execute a sh file in a Solaris, Unix, environment. How can I do it? The database environment is in Solaris and the database is 10g.
Please let me know as soon as possible.Hi,
read this <http://devtrigger.blogspot.com.br/2012/08/svn-backup-on-unix-or-solaris.html>
Or
you can to run in nohup. For example
You can a script with the command vi about your trigger and run with the sintaxe bellow:
nohup sqlplus "/as sysdba" @script.sql &
Where "script.sql" is the name of the your file.
Kind regards,
Bruno Reis.
www.brunors.com -
SQL script with host command job in Enterprise Manger Grid Control
I use Enterprise Manger Grid Control 10.2.0.5 and need to create SQL script job on database instance target on unix/linux platform.
I have problem with os command inside sqlplus script.
For example for the simple command: SQL> host ls
I get the message in output log: SQL> SQL> SQL> SQL> SQL> SQL> /bin/bash: ls: command not found
Can anyone help me?
Thank you.Hi,
Make sure you have granted all necessary rights (log on as a batch job etc.) to the user used in the prefered credentials.
Cheers,
Kenneth -
Hello folks I am trying to create a procedure to run linux host commands. I have found and used code available throughout the internet and it compiles and runs, but no matter what command I send to the host I get a 'Not Found' exception, even if I send as the command the full path to the executable. Here is my code:
*1- Java Procedure*
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 (System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) {
finalCommand = new String[4];
finalCommand[0] = "C:\\winnt\\system32\\cmd.exe";
finalCommand[1] = "/y";
finalCommand[2] = "/c";
finalCommand[3] = command;
} else { // Linux or Unix System
finalCommand = new String[3];
//finalCommand[0] = "/bin/sh";
//finalCommand[1] = "-c";
//finalCommand[2] = "'" + command + "'";
finalCommand[0] = command;
finalCommand[1] = "";
finalCommand[2] = "";
// Execute the command...
final Process pr = Runtime.getRuntime().exec(finalCommand);
// Capture output from STDOUT...
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("stdout: " + buff);
try {Thread.sleep(100); } catch(Exception e) {}
br_in.close();
} catch (IOException ioe) {
System.out.println("Error printing process output.");
ioe.printStackTrace();
} finally {
try {
br_in.close();
} catch (Exception ex) {}
// Capture output from STDERR...
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("stderr: " + buff);
try {Thread.sleep(100); } catch(Exception e) {}
br_err.close();
} catch (IOException ioe) {
System.out.println("Error printing execution errors.");
ioe.printStackTrace();
} finally {
try {
br_err.close();
} catch (Exception ex) {}
catch (Exception ex) {
System.out.println("Exception: " + ex.getLocalizedMessage());
ex.printStackTrace();
*2- PL/SQL Package*
CREATE OR REPLACE PACKAGE CIF_HOST_PKG IS
PROCEDURE host (p_command IN VARCHAR2);
END CIF_HOST_PKG;
PROCEDURE host (p_command IN VARCHAR2)
AS LANGUAGE JAVA
NAME 'Host.executeCommand (java.lang.String)';
END CIF_HOST_PKG;
*3- Java Permission*
EXEC Dbms_Java.Grant_Permission('CIF', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');
EXEC Dbms_Java.Grant_Permission('CIF', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');
exec dbms_java.grant_permission( 'CIF', 'SYS:java.io.FilePermission', '/bin/sh', 'execute' );
exec dbms_java.grant_permission( 'CIF', 'SYS:java.io.FilePermission', '/bin/ps', 'read , execute' );
exec dbms_java.grant_permission( 'CIF', 'SYS:java.io.FilePermission', '/bin/ls', 'read , execute' );
*4- Test Code*
set serveroutput on size 1000000
exec dbms_java.set_output(1000000)
exec CIF_HOST_PKG.host('/bin/ls -l');
*5- Test Output*
anonymous block completed
Exception: Exception during creation of the process: java.io.IOException: '/bin/ls -l' not found
java.io.IOException: Exception during creation of the process: java.io.IOException: '/bin/ls -l' not found
at java.lang.OracleProcess.start(OracleProcess.java:259)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:483)
at java.lang.Runtime.exec(Runtime.java:591)
at java.lang.Runtime.exec(Runtime.java:464)
at Host.executeCommand(Host:24)
Any idea on what am I doing wrong?
Thank you in advance,
AndreHas oracle user permissions to /bin/ls ?
try in sqlplus:
host /bin/ls -lIf not try chmod 777 /bin/lsElse you can try my package http://github.com/xtender/xt_svn
select * from table(XT_SVN_TEST.shell_exec('/bin/ls -l /var/tmp'))Best regards,
Malakshinov Sayan -
Problem using Host command to call a batch file
Hi all,
I am trying to call a batch file with the Host command:
host c:\test\u.bat
where u.bat calls unix2dos.exe with a parameter of d_unix.txt.
Bat file looks like this:
C:\test\unix2dos.exe d_unix.txt
PAUSE
The bat file gets called fine, but the following error occurs (in the cmd prompt):
T:\globals\ORACLE8\bin>C:\test\unix2dos.exe d_unix.txt
d_unix.txt:
Can't open file
T:\globals\ORACLE8\bin>PAUSE
Press any key to continue . . .
Running the batch file directly in windows works fine. The batch file also runs fine from the Host command if I remove the d_unix.txt parameter.
The file d_unix.txt file is in the same directory as the batch file and as unix2dos.exe.
Running from Sql Plus in a windows environment.
Any thoughts?
Edited by: dgouin on Aug 19, 2009 11:41 AM
Edited by: dgouin on Aug 19, 2009 11:42 AM
Edited by: dgouin on Aug 19, 2009 11:42 AMI always understood that it worked with whatever directory you were in when you launched the SQL*Plus binary:
D:\>SQLPLUS dbuser@testdb
SQL*Plus: Release 10.2.0.4.0 - Production on Wed Aug 19 15:26:35 2009
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Enter password:
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
dbuser@testdb > HOST ECHO %CD%
D:\
dbuser@testdb > exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
D:\>H:
H:\>SQLPLUS dbuser@testdb
SQL*Plus: Release 10.2.0.4.0 - Production on Wed Aug 19 15:27:03 2009
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Enter password:
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
dbuser@testdb > HOST ECHO %CD%
H:\
dbuser@testdb > exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options -
hi all,
are there for SAP HANA a "Host Command" (from Oracle), which you can jump from HANA studio or HANA client to the operating system "SUSE Enterprise SERVER"?
greeting
ichtoukHi Ichtouk
the sqlplus command host does not allow you to execute commands on the server you're connected to. Instead, you can execute local command without leaving your current sqlplus session.
It is by no means an open window to the Oracle servers O/S (would be bad, don't you think?).
Having said that, SAP HANA does not include a SSH client in the database client software.
If you want to access the SAP HANA server on O/S level, you really need to use a proper SSH client with a regular O/S user logon.
- Lars -
Hi every one,
I am trying to run an sql script in oracle forms.
I know that it can be done using HOST command.
But I dont know how to use it.
Can any one give me one example how to use the host command in the oracle forms.
Thanks,
rajuSomething like this:
HOST ( 'sqlplus scott/tiger@dbtest @C:\mysqlfiles\myscript.sql') -
Can PL/SQL Run Host Command (DOS Command) ??
Hi All,
Can PL/Sql run HOST Command ?
If can't, iis there any other way to execute the DOS command ?
Thanks for help.
IwanHi sarah,
i have tried, but it didn't work.
in my abc.sql script : (host in pl/sql level)
BEGIN
HOST('cmd /C dir *.*');
END;
exit
but it still didn't work
so i tried in sqlplus level :
variable vStatus VARCHAR2(1);
variable vCmd VARCHAR2(3000);
BEGIN
:vCmd := 'C:\Program Files\Internet Explorer\iexplore';
END;
HOST("C:\Program Files\Internet Explorer\iexplore");
EXIT;
if i put HOST("C:\Program Files\Internet Explorer\iexplore"); --> it worked....
If i put HOST(:vCmd); --> i won't work.
Any body can help ?
Thanks,
Iwan -
Host command not showing the output
Hi,
I am not able to view the host command's output from sqlplus(i am using an windows XP OS).
The commands i tried:
SQL> $whoami
SQL> host whoami
SQL> !whoami
-Thanks
Boopathy VasagamSolomon Yakobson wrote:
And keep in mind, SQL*Plus command host will open a command window, execute command and will close command window To avoid this you can use:
host cmd /k echo %USERNAME%or
host cmd /k echo %USERDOMAIN%\%USERNAME%Then SQL*Plus will open command window, execute echo command and will not close command windows (since /k was used). You will have to manually issue exit command in command window to close it.
SY.
Maybe you are looking for
-
IP Configuration Error - IP address in use by another device
My parents' have set up a wirless netwrok in their home but are experiencing a IP configuration error. They have Cable Broadband going into a cable modem. The modem is connected to a DLINK router via ethernet. The router has an ethernet connection to
-
Just upgrade my MacBook Pro Mid 2010 to Mountain Lion and tried to connect with Apple TV 3th gen. through Airplay and couldn't mirrorring video on my LG Smart TV screen. Just paid US 99.00 for Apple TV plus US 19.99 to Mountain Lion for nothing @?$%
-
Can't connect via Airport on a formerly working system
Hi, I could really use some help here! I have a new MacBook (and generally love it). At both home and work I have DSL set up (both wireless and cables in both) and until recently used only PCs. In both settings, I have security set up that requires e
-
I run Protools.. It does not work with 10.9.4 I forgot to check compatibility before I updated OSX I need 10.9.3 Combo update I cannot load that as the message says I can't. The only help I've seen involves time machine back ups- which i don't us
-
Balance of SECess on Service tax not in J2IUN
Hello: I can get the balance of SECess on Service tax not in J2IUN. How can I do? And the table:J_1IEXCACC new added 3 field are about what kind of account? RG23A AT1-AT3 RG23C AT1-AT3 What kind of account should I assign to these fields? BR, Linda