Sqlplus invoking ksh shell code

I have the following code:
sqlplus -s / <<EOT
SET PAGESIZE 0
SET FEEDBACK OFF
SET VERIFY OFF
spool grant.sql
SELECT 'GRANT SELECT ON ' || u.owner || '.' || u.object_name ||' TO xxx_role;'
FROM dba_objects u WHERE u.object_type IN ('TABLE','VIEW','SEQUENCE')
and owner = 'YYY';
spool off
EOT
Is there a way in the SQL block above I can test to see if my spool file contains data instead of invoking sqlplus again to run the spool file?
I would like to do something like this in the first block if possible or something very similiar.
As this will be run in a loop and will be passed values I want to make it go as quick as possible
and therefore limit the number of times I need to startup SQLPLUS
if [ -s spool.sql ]
then
@@spool.sql
fi

Assuming you are calling the first script fromm a shell script, then something like:
/export/home/oracle> cat t.sh
sqlplus -s / <<EOT
SET PAGESIZE 0
SET FEEDBACK OFF
SET VERIFY OFF
spool grant.sql
SELECT 'GRANT SELECT ON ' || u.owner || '.' || u.object_name ||' TO xxx_role;'
FROM dba_objects u WHERE u.object_type IN ('TABLE','VIEW','SEQUENCE')
and owner = 'YYY';
spool off
EOT
if [ -s grant.sql ]; then
  echo 'Run grants.sql'
else
  echo 'no grants'
fiWhen you run it it gives:
/export/home/oracle> ./t.sh
no grantsJust substitute another here document for the echo run grants.sql line. If you are passing parameters to the shell script, then substitute thos for the hard coded bits.
John

Similar Messages

  • How to invoke a shell script using java

    Hi
    I am trying to invoke a shell script(unix) using java and I have tryied to load the shell using exec(cmd) and then trying to execute the shell.
    But it is not working.
    Can you please guide me on this matter.

    Hi I am facing the same problem
    I want to call a shell script through java in linux system of course.
    I am using the following section of code .
    public class LinuxServer {
         public static void main(String args[]){
              Runtime r = Runtime.getRuntime(); //get runtime information
              try
              Process Child = r.exec("/usr/bin/ksh") ; //execute command
              BufferedWriter outCommand = new BufferedWriter(new OutputStreamWriter(Child.getOutputStream()));
              outCommand.write("/opt/jboss-4.0.0/test1.sh");
              outCommand.flush();
              try
              Child.waitFor(); //wait for command to complete
              catch(InterruptedException e)
              { //handle waitFor failure
              System.out.println("ERROR: waitFor failure");
              System.exit(10); //exit application with exit code 10
              catch(IOException e)
              { //handle exec failure
              System.out.println("ERROR: exec failure"+e);
              System.exit(11); //exit application with exit code 11
    But when I am compiling and running this script in the linux system,
    Its giving the following error.
    Exception in thread "main" java.lang.NoClassDefFoundError: while resolving class: LinuxServer
    at java.lang.VMClassLoader.resolveClass(java.lang.Class) (/usr/lib/libgcj.so.5.0.0)
    at java.lang.Class.initializeClass() (/usr/lib/libgcj.so.5.0.0)
    at java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/lib/libgcj.so.5.0.0)
    at java.lang.Class.forName(java.lang.String) (/usr/lib/libgcj.so.5.0.0)
    at gnu.gcj.runtime.FirstThread.run() (/usr/lib/libgcj.so.5.0.0)
    at JvThreadRun(java.lang.Thread) (/usr/lib/libgcj.so.5.0.0)
    at JvRunMain(java.lang.Class, byte const, int, byte const, boolean) (/usr/lib/libgcj.so.5.0.0)
    at __gcj_personality_v0 (/opt/jboss-4.0.0/java.version=1.4.2)
    at __libc_start_main (/lib/tls/libc-2.3.4.so)
    at JvRegisterClasses (/opt/jboss-4.0.0/java.version=1.4.2)
    Caused by: java.lang.ClassNotFoundException: java.lang.StringBuilder not found in [file:/usr/local/staf/lib/JSTAF.jar, file:/usr/local/staf/samples/demo/STAFDemo.jar, file:/home/db2inst4/sandip/staf/lib/JSTAF.jar, file:/home/db2inst4/sandip/staf/samples/demo/STAFDemo.jar, file:/usr/share/java/libgcj-3.4.3.jar, file:./, core:/]
    at java.net.URLClassLoader.findClass(java.lang.String) (/usr/lib/libgcj.so.5.0.0)
    at gnu.gcj.runtime.VMClassLoader.findClass(java.lang.String) (/usr/lib/libgcj.so.5.0.0)
    at java.lang.ClassLoader.loadClass(java.lang.String, boolean) (/usr/lib/libgcj.so.5.0.0)
    at JvFindClass(_Jv_Utf8Const, java.lang.ClassLoader) (/usr/lib/libgcj.so.5.0.0)
    at java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/lib/libgcj.so.5.0.0)
    at JvBytecodeVerifier.verify_instructions_0() (/usr/lib/libgcj.so.5.0.0)
    at JvVerifyMethod(_Jv_InterpMethod) (/usr/lib/libgcj.so.5.0.0)
    at JvPrepareClass(java.lang.Class) (/usr/lib/libgcj.so.5.0.0)
    at JvWaitForState(java.lang.Class, int) (/usr/lib/libgcj.so.5.0.0)
    at java.lang.VMClassLoader.linkClass0(java.lang.Class) (/usr/lib/libgcj.so.5.0.0)
    at java.lang.VMClassLoader.resolveClass(java.lang.Class) (/usr/lib/libgcj.so.5.0.0)
    ...9 more
    Pls help

  • How to invoke BASH shell and execute a command in that shell in Windows 98

    Hello, I have a problem and if somebody will help me, I will be very glad. Thank you.
    I am using BASH shell on Windows 98 OS by means of CYGWIN. And I want to invoke this BASH shell and execute a preprogrammed command in the shell (./scan fileName.txt) from a JAVA program. But so far, I am not sucessful. I can not read or write anything from / to BASH shell. It either blocks and freezes (When I use waitFor( ) ) or appears and disappears without executing scan command (When I do not use waitFor( ) ). My code is like this:
    // This method is used for compiling a file.
    // It invokes BASH shell and executes "./scan fileName.txt" command
    public void compileFileMethod () {
    try {
    Process proc = ( Runtime.getRuntime() ).exec ("C:\\MyDocuments\\CYGWIN.BAT); //I also tried to add -c ./scan fileName.txt after .BAT );
    // I also tried to write "C:\\MyDocuments\\BASH.EXE" but it did not help
    OutputStream ostr = proc.getOutputStream();
    BufferedWriter bw = new BufferedWriter ( new OutputStreamWriter (ostr) );
    InputStream istr = proc.getInputStream();
    BufferedReader br = new BufferedReader ( new InputStreamReader (istr) );
    InputStream errorStr = proc.getErrorStream();
    BufferedReader errorBr = new BufferedReader ( new InputStreamReader (errorStr) );
    bw.write("scan case40.10.txt"); /* I am trying to input the scan command to the shell,but it is not working*/
    bw.flush();
    Vector list = new Vector (1) ;
    String str;
    while ( (str = br.readLine() ) != null) {
    list.addElement(str);
    } // End of while
    Enumeration enumForList = list.elements();
    while ( enumForList.hasMoreElements() ) {
    String tempString;
    tempString = ( String ) enumForList.nextElement();
    System.out.println(tempString); // I am trying to read the outputs of the scan command but it is not reading (I can not see any output)
    I tried with and without waitFor( ), it did not work
    // wait for command to terminate
    proc.waitFor();
    // close streams
    br.close();
    bw.close();
    errorBr.close();
    } // End of try
    catch ( IOException ioe ) {
    JOptionPane.showMessageDialog (null, "Input / output error occured while compiling file ", "Error", JOptionPane.ERROR_MESSAGE);
    } // End of catch
    catch ( SecurityException se ) {
    JOptionPane.showMessageDialog (null, "Security error occured while compiling file ", "Error", JOptionPane.ERROR_MESSAGE);
    catch ( InterruptedException ie ) {
    JOptionPane.showMessageDialog (null, "Interruption error occured while compiling file ", "Error", JOptionPane.ERROR_MESSAGE);
    } // End of method compileFileMethod
    // Thank you for your helps and time.

    You cannot invoke BAT files directly, you have to invoke the program that run those files which is your Windows 98 shell. For example (under windows 2000), i would invoke "cmd.exe sricpt.bat some args", rather than "script.bar some args".
    Hope this will help you out.

  • How to invoke dos shell from java program

    Hi,
    I'm not able to invoke dos shell from java.
    Can any one help me in this issue.
    I'm providing the source code below:
    try{
    Runtime.getRuntime().exec("cmd.exe")
    catch(IOException e) {
    System.out.println(e.getStackTrace());
    Thanks

    Does it throw a different exception?
    Or does it just do nothing at all?
    It does nothing at all[/b
    Is this a standalone Java app?
    Or a Java Applet running via a webbrowser? [b]It's a standalone application

  • UIKit, Metric Logs, Kern_Invalid, Shell Code execution

    I use i Phone version 7.1.2 and I am new to apple. I am curious to know if anyone in the community has noticed "bug_type";"193"os_version":"iPhone OS 7.1.2, It seems as though the system crash report states, Exception Type:EXC_BAD_ACCESS (SIGSEGV), Exception Subtyp: Kern_Invalid_Address at 0x0000000015d592c8 triggered by Thread 0 or bug_type";176, found under General, About,  diagnostic and usage data.
    Or if anyone in the community has also seen awdd-2014-09-11-001040-3.consolidated.metriclog. It seems as if a UIKit is involved similar to cunzhang from Adlab of Venustech, and Ian Beer of Google Project ZOO's findings.
    It seems as though crashes are occurring on the phone using shell code execution and UIKit's I am unaware of a patch or software update. Although I have been privy to the wild card diginotar fake ssl certs, in the past.
    Has anyone else seen or encountered Data subject FlashStatus-2014-09-10-234947.ips.synced bug type 176, Setup_2014-09-10-075848_iPhone.ips bug type 109, concerning airport settings, bud_2014-)9-11-171830_Metric-Log-Inc.ips Path System Library Private Frameworks, crashed triggered byThread 5 0libsqlite3.dylib+139484 0x000000001995a0dc 0x199518000. 
    I have shown this to Apple employees and they stated I may need to contact a programmer.
    I have contacted Apple directly brought this to their attention, they are, as always very supportive. But, I believe I need a programmer as this is above my expertise. Any help from the community would be appreciated. Even a link to where I can find out more would be helpful.

    Yes, thank you. This is the closest solution to my problem.
    However, I will now introduce host_profile host agent.
    But I can not understand where exactly did I lack rights to the agent?
    ======================
    SAPSYSTEMNAME = SAP
    SAPSYSTEM = 99
    service/porttypes = SAPHostControl SAPOscol SAPCCMS
    service/admin_users = daaadm sapadm
    DIR_LIBRARY = /usr/sap/hostctrl/exe
    DIR_EXECUTABLE = /usr/sap/hostctrl/exe
    DIR_PROFILE = /usr/sap/hostctrl/exe
    DIR_GLOBAL = /usr/sap/hostctrl/exe
    DIR_INSTANCE = /usr/sap/hostctrl/exe
    DIR_HOME = /usr/sap/hostctrl/work
    service/logfile_000 = /tmp/s
    service/logfile_001 = /usr/sap/DAA/SMDA97/SMDAgent/log/smdagent_trace*.trc
    service/logfile_002 = /usr/sap/DAA/SMDA97/SMDAgent/log/smdagent_trace.*.trc
    service/logfile_003 = /usr/sap/SLM/DVEBMGS00/j2ee/cluster/dispatcher/log/applications*.log
    service/logfile_004 = /usr/sap/SLM/DVEBMGS00/j2ee/cluster/dispatcher/log/applications.*.log
    service/logfile_005 = /usr/sap/SLM/DVEBMGS00/j2ee/cluster/dispatcher/log/defaultTrace*.trc
    service/logfile_006 = /usr/sap/SLM/DVEBMGS00/j2ee/cluster/dispatcher/log/defaultTrace.*.trc
    service/logfile_007 = /usr/sap/SLM/DVEBMGS00/j2ee/cluster/server0/log/applications*.log
    service/logfile_008 = /usr/sap/SLM/DVEBMGS00/j2ee/cluster/server0/log/applications.*.log
    service/logfile_009 = /usr/sap/SLM/DVEBMGS00/j2ee/cluster/server0/log/applications/com.sap.xi/xi*.log
    service/logfile_010 = /usr/sap/SLM/DVEBMGS00/j2ee/cluster/server0/log/applications/com.sap.xi/xi.*.log
    service/logfile_011 = /usr/sap/SLM/DVEBMGS00/j2ee/cluster/server0/log/defaultTrace*.trc
    service/logfile_012 = /usr/sap/SLM/DVEBMGS00/j2ee/cluster/server0/log/defaultTrace.*.trc
    ======================

  • Invoking external C code from Oracle

    How do I invoke external C code on another machine from Oracle?
    I need certain queries in Oracle to trigger a call to C code that is running on a different machine. We need to find out which architecture is suited to this.
    We plan to port this solution to other databases in the future, so it would be better if the solution was platform independent.
    Thanks

    What is the API to this C code?
    What, exactly, would you be looking for in a platform independent way to invoke C code from a database? You can build a web service interface to the C code, which would provide a relatively database independent interface to various databases. But the Oracle code that would call the web service would be very much database specific. As would the code in any other database to call a web service. Plus if you're talking about data mining, you're probably talking about transferring a rather large volume of data from the database, which would generally make web services and the associate XML a rather inefficient data transfer mechanism.
    Most databases have the ability to generate a flat file as well, but that tends to be a rather database-dependent API.
    Can the C code not extract the data from the database? There are a ton of somewhat database independent APIs that would allow a client application extract data from a variety of databases.
    Justin

  • Invoking Menu through Code

    Is there any way I can invoke the menu code when I press a button in the form. The menu is attached to form.
    Thanks in advance.

    Hi Rajesh,
    The form object has a mode property which you can set to change the current mode of the form. This should allow you to open a form and set its default mode through code to Find (fm_FIND_MODE).
    Kind Regards,
    Owen

  • Invoke a shell script

    Hi!I am trying to invoke a shell script from within my JSP. I have tryed with Runtime().exec and Runtime.getRuntime().exec(), but it doesn't works. Does anybody Know how I can do it?

    If you are using a iPlanet Web server 6.0 try "exec" tag.

  • Invoking unix shell scripts from java?

    Hi,
    could someone explain to me how one wuld invoke unix shell scripts from java.
    Also, could you invoke Visual Basic scripts from java.
    Finally, could you do this from an EJB?
    thanks for any help....
    sudu

    I just posted a snippet of this solution in the topic about widows commands chech it out it works just fine for unix shell scripts.
    --Ian                                                                                                                                                                                                                                                                                       

  • Invoke a shell script from java

    hi all
    does anyone know how to invoke a shell script from your java program?
    thanks
    udam

    Use Runtime.exec(), make sure your script is executable, and make sure it starts with something like #!/bin/sh

  • Invoking a shell script from JSP

    Hi,
    I am trying to invoke a shell script from within my JSP. I need to pass a few parameters to this shell script also. The shell script then returns a string value to the JSP. Any ideas, how to acheive this? I would appreciate any help.
    Thanks,
    Fauzia

    implement a method somewhere that uses Runtime.exec() internally. see here:
    http://java.sun.com/j2se/1.3/docs/api/index.html
    robert

  • Running sqlplus scripts from Java code?

    hi
    I need to programmatically run sqlplus scripts from Java code on a machine that doesn't have sqlplus installed.
    Is there any Java class library available for doing this?

    The Ant approach could probably work for me, thanks for the tip.
    The setup seems rather complex however, given the simplicity of the task. I would prefer just running a Java based SQL*Plus from in a separate process or doing this via an API that would allow me to run SQL*Plus scripts (parse script, substitute variables, run statements).
    Oracle SQL Developer v1.1 appears to include an API that does exactly this.
    The ScriptParser, Substitution and SQLPLUS classes in the oracle.dbtools.raptor.scriptrunner package (oracle.sqldeveloper.jar) seem to do just what I need based on my tests.
    Can I use these classes for this purpose in my application? Is repackaging allowed?
    Does Oracle have any plans for releasing this sort of functionality separately e.g. as part of the Instant Client?

  • Output format of sqlplus commands under shell script

    hi experts
    Can you help with some problems please?
    1.) I try to run shell script from dbms_scheduler, which runs sqlplus and the output of sqlplus commands is written to file using command spool. To this point everything is running ok.
    My problem is, that output of this file is: (e.g.)
    SQL> PROMPT ****************USERB******************
    ****************USERB******************
    SQL> --SELECT sid
    SQL> -- FROM v
    SQL> -- WHERE audsid = SYS_CONTEXT('userenv','sessionid');
    But I don't want the whole first line in the output file. I only want the output of this command, like on the second line.
    2.) How Can I write two outputs from sqlplus using command spool running at the same time into one file?
    Like in first issue described above. The main sqlplus create a job and this execute the background sqlplus using shell script. But both, the main and the background sqlplus are written to output file at the same time. But only one is written into. But I want the both outputs in the file.
    How Can I do that, if I can?
    Thanks a lot.

    user9357436 wrote:
    hi experts
    Can you help with some problems please?
    1.) I try to run shell script from dbms_scheduler, which runs sqlplus and the output of sqlplus commands is written to file using command spool. To this point everything is running ok. then why are you here?
    My problem is, that output of this file is: (e.g.)
    SQL> PROMPT ****************USERB******************
    ****************USERB******************so remove PROMPT line from the file
    >
    SQL> --SELECT sid
    SQL> -- FROM v
    SQL> -- WHERE audsid = SYS_CONTEXT('userenv','sessionid');
    But I don't want the whole first line in the output file. I only want the output of this command, like on the second line.
    2.) How Can I write two outputs from sqlplus using command spool running at the same time into one file?you can not do so.
    Like in first issue described above. The main sqlplus create a job and this execute the background sqlplus using shell script. But both, the main and the background sqlplus are written to output file at the same time. But only one is written into. But I want the both outputs in the file.
    How Can I do that, if I can?Can't.
    Now what?
    >
    Thanks a lot.Why using DBMS_SCHEDULER to invoke OS script to run sqlplus that runs SQL statements?
    this is like making THREE Left Turns, instead of single Right Turn.
    Just invoke PL/SQL procedure that does what needs to be done.

  • Can i invoke Unix Shell Script using JSP or Java

    Hi
    I am working on developing web application .In this application user will upload a file and this file will be stored on server .once the file is saved i have to invoke shell script which triggers the informatica process to read the file content.
    Can some please assist me on this. If any one have pseudo code for this it will be of great help
    Thanks

    This article has example code and explains how to use it.
    You should read the entire article first.
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • Running SQLPLUS from UNIX shell script

    I'm not sure if this is the right forum, but...
    How can I execute a sql file from inside the UNIX shell script, logging on to Oracle w/o supplying a UID/pwd? Normally, we log into UNIX using our own logon, then sudo as another user to login to Oracle. Now, I'm trying to create a UNIX shell script, where I'm already sudo'd as the UserID that logs into Oracle. I've tried the following, but can't get it to work. I'm a UNIX scripting noob. Any ideas?
    example:
    #! /usr/bin/ksh
    sqlplus / \@test.sql << EOF
    exit;
    EOF

    I'm a UNIX scripting noob.In which case I feel obligated to point you at William Robertson's excellent article Database Shellscripts Considered Harmful. Save yourself a world of pain.
    Cheers, APC

Maybe you are looking for