Executing a shell script from a jsp page

Hi,
I'm facing a problem while executing a shell script from a jsp page.
I'm using Runtime.exec() function.
It's working fine for single statement scripts.But if the script consists of any database processing and some other processing statements,it's not returning the correct exit status of the process.
Will u please help me in this.
If there is any other ways to execute a shell script from a jsp page other than Runtime.exec() like RMI etc,.If so let me know.
Thanks in advance.

Hello,
It's hard to help you but what you can do is listening to the outputs of your script, you should read the output stream and error stream and send them to the default console.
Check this excellent article : http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=4
Best regards,
Olivier.

Similar Messages

  • Executing a shell script from a java program

    Hi,
    I'm facing a problem while executing a shell script from a jsp page.
    I'm using exec() function.
    It's working fine for single statement scripts.But if the script consists of any database processing and some other processing statements,it's not returning the correct exit status of the process.
    Will u please help me in this.
    If there is any other ways to execute a shell script from a jsp page other than Runtime.exec().If so let me know.
    Thanks in advance.

    I think this shud workMaybe - but it is wrong! Why do you create aReader
    and then read bytes which are turned into a String
    without worrying about whether or not the bytes area
    String and without worrying about the character
    encoding if the bytes do represent characters and
    without worrying about how many bytes wereactually
    read.
    Also, both you and the OP should read, digest and
    follow the advice given in
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-
    traps.htmlI dont care if it is wrong. This code works for me.
    We are here to solve problems not to find which post
    is wrong.It is wrong! You are posting bad advice that is very wrong! It may work for you but it is wrong in general! WRONG WRONG WRONG.
    If you have a solution then post it I did post a solution! The reference I gave will explain to you and the OP exactly how it should be done.
    rather then
    posting rude comments.I was not rude! I was explaining just some of what was wrong!

  • Error while executing unix shell script from java program

    Hi All,
    I am trying to execute unix shell script from a java program using Runtime.execute() method by passing script name and additional arguments.
    Code snippet :
    Java Class :
    try{
         String fileName ="test.ksh";
         String argValue ="satish"; // value passed to the script
         String exeParam = "/usr/bin/ksh "+fileName+" "+argValue;
         Process proc = Runtime.getRuntime().exec(exeParam);
         int exitValue = proc.waitFor();
         sop("Exit Value  is : "+exitValue);
    catch(Exception e)
    e.printStackTrace();
    }Test.ksh
      export -- application realated paths..
      nohup  abc.exe 1> test.log 2>&1;
      $1
      exit.By running the above java class , i am getting exit Value: 139 and log file test.log of 0 bytes.
    when i am running the same command (/usr/bin/ksh test.ksh satish) manually, it's calling abc.exe file successfully
    and able generate the logs properly.
    Pls let us know where exactly i am stuck..
    Thanks in advance,
    Regards,
    Satish

    Hi Sabre,
    As per the guidelines provided by the article, i had done below changes..
    InputStream is = null;
    InputStreamReader iStreamReader = null;
    BufferedReader bReader = null;
    String line = null;
    try{
    String fileName ="test.ksh";
    String argValue ="satish"; // value passed to the script
    String exeParam = "/usr/bin/ksh "+fileName+" "+argValue;
    Process proc = Runtime.getRuntime().exec(exeParam);
    is = proc.getErrorStream();
    iStreamReader = new InputStreamReader(is);
    bReader = new BufferedReader(iStreamReader);
    System.out.println("<ERROR>");
    while((line = bReader.readLine()) != null)
    System.out.println("Error is : "+line);
    System.out.println("</ERROR>");
    int exitValue = proc.waitFor();
    sop("Exit Value is : "+exitValue);
    catch(Exception e)
    e.printStackTrace();
    Now , it's showing something like..
    <ERROR>
    </ERROR>

  • How to execute unix shell script from Java ...

    Hi,
    Anyone know how to execute unix shell script from Java?
    Suppose I have several shell scripts written in perl or tcl or bash.
    I just want to catch the output of that script.
    Is there any ready to use module/object for this?
    Please let me know, this is quite urgent for my study assigment.
    Thanks in advance,
    Regards,
    me

    Look up Runtime.exec()

  • Execute a shell script from inside PL procedure

    Oracle 9205 on Red Hat Enterprise Linux 3.
    Is there any way to execute an O.S. shell script from inside a PL/SQL procedure?
    This is, that PL_SQL procedure evaluate a situation and if the condition is true, it calls and execute an O.S. shell script.

    PL/SQL procedures do not support any native calls to the OS; however, you can code calls to external procedures or JAVA procedures to perform tasks on the OS.
    Prior to these two methods any of the following packages dbms_alert, dbms_pipe, or utl_file could be combined with a daemon type program to issue OS commands, run shell scripts, etc....
    There is a writeup on metalink with examples.
    HTH -- Mark D Powell --

  • Executing a shell script from a form (client / server)

    From a form in a client server environment, I would like to execute a shell script on the server.
    Environment:
    Server: SunOS 5.6
    DB : 8.0.5
    Forms : Developer 6 w/patch 6A
    Forms - 6.0.5.34.0

    Jim,
    Yes. Use the host command from forms and call the command rexec.
    Raymond
    null

  • Example: Executing a shell script from java

    Hi. There are many other posts in the forums related to executing a unix script from java, but I wanted to post another example that I thought might be helpful...
    The key thing to executing the script is to include the -c switch for the sh command. This tells the sh command that you are passing a string to be interpreted as input. Without this switch, the script does not execute as you'd expect it to. Also, use a string array to pass each part of the sh command.
    Here is a working sample class, along with a test script to execute it:
    public class TestShellScript {
    public static void main(String[] args)
    String[] chmod = {"chmod","777","testscript1"};
    String[] runscript = {"sh","-c","./testscript1 > jdata.out"};
    Runtime rtime = Runtime.getRuntime();
    try
    rtime.exec(chmod); // Set the authorities for testing
    rtime.exec(runscript); // Run the script with redirection
    catch (IOException e)
    e.printStackTrace();
    rtime = null;
    Here is a test script to wrap the java call:
    #!/bin/sh
    cd /<your script dir>
    export -s CLASSPATH=/<your jar dir>/TestShellScript.jar
    export -s PATH=/<your script dir>:/usr/bin
    java TestShellScript
    - Hope this helps.

    I don't know exactly but the code written below is working fine try the same with your code .Even with your code instead running the code with
    " ./<filename> ",if you execute it with "sh <filename>" command without changing the mode of the file it is executing properly.
    import java.io.*;
    import java.util.*;
    public class ScriptBuilder
    public ScriptBuilder()
    public void writeScript() throws java.io.IOException
    FileWriter writer = new FileWriter(new File("test_script"));
    writer.write("#! /bin/sh\n");
    writer.write("ll>/home/faiyaz/javaprac/checkll");
    writer.flush();
    writer.close();
    Runtime rt= Runtime.getRuntime();
    rt.exec("chmod 777 test_script");
    rt.exec("./test_script");
    } public static void main (String[] args)throws java.io.IOException
    ScriptBuilder sb = new ScriptBuilder();
    sb.writeScript();
    }

  • Executing a shell script from a web deployed form

    Hi there,
    i've got a web deployed form from which i want to execute a UNIX shell script upon clicking a button.. I've used the host command ,and the rsh utility in Windows NT but i'm getting an error message saying
    "machine address" Permission denied, rsh can't establish connection " this is the code in the when button pressed trigger
    HOST('c:\windows\system32\rsh <<machine address>> opt/apps/wmc/rw.ksh');
    the machine address being the unix machine i'm trying to connect to and the last part being the path and the shell script to be executed..
    can anybody help me out here ????
    Regards
    wole
    null

    Jim,
    Yes. Use the host command from forms and call the command rexec.
    Raymond
    null

  • Executing a shell script from pl/sql stored procedure

    Hi,
    I have Oracle 8i on HP-UX.
    I am passing a shell script name as a parameter to a user defined function from a pl/sql stored procedure. This user defined function has insterface to a user defined Java class file in Aurora java virtual machine which is written using runtime class which can execute any OS command or any shell script. I am getting any OS command run successfully, but could not run my own shell script. It's is not getting environment variables of my own, so not getting executed. So please suggest how can get these env variables in my shell script and also suggest other sucurity concerns to be taken into consideration.
    If you have any questions please let me know.
    This is really a very urgent issue.....
    Please help me.
    Thanks
    Srinivasa Rao Kolla

    Your best bet is to use the dbms_pipe builtin package to send the command to the host

  • Executing SAP GUI Script From a Web Page

    I have an issue when trying to execute some javascript (sap gui script) from a webpage. 
    When the javascript is executed I get the message:
    automation server unable to create object. 
    However, this exact same javascript when placed in a text file and double-clicked executes just fine through the windows scripting host. 
    Does anyone have an example of gui script code executing from a webpage?  Or any ideas on why it isn't working from the webpage?  Both scenarios should be executing the code on the local machine through WSH.
    Below is the javascript as well as the webpage executing the javascript:
    SAPGUI SCRIPT
    if (typeof(application) == "undefined")
       sapgui      = GetObject("SAPGUI");
       application = sapgui.GetScriptingEngine;
    if (typeof(connection) == "undefined")
       connection = application.children(0);
    if (typeof(session) == "undefined")
       session = connection.children(0);
    if (typeof(WScript) != "undefined")
       WScript.connectObject(session, "on");
       WScript.connectObject(application, "on");
    session.findById("wnd[0]").maximize();
    session.findById("wnd[0]/tbar[0]/okcd").text = "/nzsd1067";
    session.findById("wnd[0]").sendVKey(0);
    session.findById("wnd[0]/usr/ctxtVBAK-KUNNR").text = "6343";
    session.findById("wnd[0]").sendVKey(0);
    WEBPAGE
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
         <head>
              <title></title>
              <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
              <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
              <! INPUT PARAMETER SETTINGS:
              To Push data to Siebel or SAP the appropriate
              field below must be set = TRUE.
              Pop_SAP
              Pop_Siebel
              SIEBEL INPUT PARAMETER: When
              Pushing data to a Siebel screen the Query_Type should be set based on the type
              of lookup that is requested.
              Query_Type = 'SAP' -presents a screen based on a customer SAP Id.
              Query_Type = 'SR' -presents a screen based on a Service Request.
              Query_Type = '' or null -presents a search screen to locate the proper contact in Siebel
              APP_SAP_ID -SAP customer Id
              APP_SR_NUM -Siebel Service Request Number
              >
    <SCRIPT LANGUAGE="VBScript">
    Sub LoadContact()
            'Siebel Application Object
            Dim siebApp 'As SIEBELHTMLLib.ISiebelHTMLApplication
            Dim siebSvcs 'As SIEBELHTMLLib.ISiebelService
            Dim siebOutputPropSet 'As SIEBELHTMLLib.ISiebelPropertySet
            Dim siebInputPropSet 'As SIEBELHTMLLib.ISiebelPropertySet
            Dim bool 'As Boolean
            Dim errCode 'As Integer
            Dim errText 'As String
            Dim QueryType 'As String
         Dim PopSAP 'As String
         PopSiebel = "TRUE"
         If PopSiebel = "TRUE" Then
              QueryType = "SAP"
              If QueryType = "null" Then
                   QueryType = ""
              End If
                 'Create The SiebelHTML Object      
                 set siebApp = CreateObject("SiebelHTML.SiebelHTMLApplication.1")  
                 If Not siebApp Is Nothing Then
                     'Create A New Property Set
                     set siebInputPropSet = siebApp.NewPropertySet
                     set siebOutputPropSet = siebApp.NewPropertySet
                     If Not siebInputPropSet Is Nothing Then
                         siebInputPropSet.SetProperty "ANI", "9738986011"
                         siebInputPropSet.SetProperty "SAP_ID", "0000516616"
                         siebInputPropSet.SetProperty "SR_NUM", "null"
                         siebInputPropSet.SetProperty "Interaction_ID", "168608840053"
                         siebInputPropSet.SetProperty "Query_Type", QueryType
                     Else
                         errCode = siebApp.GetLastErrCode
                         errText = siebApp.GetLastErrText
                             MsgBox "Could not Create Siebel Property Set: " & errCode & "::" & errText
                     End If
                     'Get A Siebel Service
                     set siebSvcs = siebApp.GetService ("TAWBS")
                     If Not siebSvcs Is Nothing Then
                         siebSvcs.InvokeMethod "TAWPresentAccount", siebInputPropSet, siebOutputPropSet
                  Else
                         errCode = siebApp.GetLastErrCode
                         errText = siebApp.GetLastErrText
                   MsgBox "Could not Get Siebel Service: " & errCode & "::" & errText
                         End If
                     set siebApp = Nothing
                 End If
                 set siebInputPropSet = Nothing
                 set siebOutputPropSet = Nothing
                 set siebSvcs = Nothing
         End If 
    End Sub
    </SCRIPT>
    <SCRIPT LANGUAGE="javascript">
    function loadSAP()
         if (typeof(application) == "undefined")
              sapgui      = GetObject("SAPGUI");
              application = sapgui.GetScriptingEngine;
         if (typeof(connection) == "undefined")
              connection = application.children(0);
         if (typeof(session) == "undefined")
              session = connection.children(0);
         if (typeof(WScript) != "undefined")
              WScript.connectObject(session, "on");
              WScript.connectObject(application, "on");
         session.findById("wnd[0]").maximize();
         session.findById("wnd[0]/tbar[0]/okcd").text = "/nzsd1067";
         session.findById("wnd[0]").sendVKey(0);
         session.findById("wnd[0]/usr/ctxtVBAK-KUNNR").text = "0000516616";
         session.findById("wnd[0]").sendVKey(0);
    } // end
    </SCRIPT>
    </head>
         <body onload="loadSAP()">
              <H3><FONT face="Arial" size="5">Raytheon Integration Screen</FONT></H3>
              <HR style="WIDTH: 882px; HEIGHT: 8px" color="#3366cc" SIZE="8">
              <form id="ValidForm" onsubmit="LoadContact(); return false;" language="jscript">
                   <FONT face="Arial">Load Siebel Screen</FONT> <! <input name="Text1" TYPE="TEXT"
                   SIZE="10" ID="Text1"> <input name="Submit" TYPE="submit" VALUE="Submit" ID="Submit1">
              </form>
              <form id="Form1" onsubmit="loadSAP(); return false;" language="javascript">
                   <FONT face="Arial">Load SAP Screen</FONT>    <! <input
                   name="Text2" TYPE="TEXT" SIZE="10" ID="Text2"> <input name="Submit" TYPE="submit" VALUE="Submit" ID="Submit2">
              </form>
         </body>
    </html>

    Hi Bernd,
    the following code works in VBS. If you run saplogon.exe you'll get a message box saying '/app'.
    Set Wrp = CreateObject ("SapROTWr.SapROTWrapper")
    Set SapGui = Wrp.GetROTEntry ("SAPGUI")
    Set application = sapgui.GetScriptingEngine
    MsgBox application.id
    I haven't tried it on a web page, but I don't see why it shouldn't work there. Ok, maybe the MsgBox is command is not available.
    Best regards,
    Christian

  • Executing a shell script from a Trigger

    All,
    I have to write a script to do the following requirement.
    There is a file called BUSINESS_DATE.TXT.
    This file get updated once the oracle partition created. In Oracle, Partition will be created every day. There is a seperate script scheduled to take care ORACLE partition creation.
    The above file will have only one row. i.e
    03092012
    If Oracle partition creation job failed, the above file won't be updated.
    My requirement is,
    I have to check whether the BUSINESS_DATE file is updated today or not. If yes, I will have to move the files from common area to input file directory to process those files.
    All file name will amend with current date.
    i.e
    LIDDIFD03092012.TXT
    The key part is to check the BUSINESS_DATE.TXT file is updated properly or not.
    We don't know what time the file will get updated. So we are planning to schedule the new script to run for every 15 mins to check whether the file is updated or not
    But...I just thougt instead of writing a shell script to do the above one, Why shouldn't I capture the date in a table (New table needs to be created) and use ORACLE TRIGGER to run the shell script to move the files from common area to input file directory to process those files?
    My Proposal in ORACLE :
    Create table business_date
    rep_date varchar(15),
    curr_timestamp timestamp
    Once the oracle partition created , one row will be inserted into the above table. This adjustment needs to be implemented partition script.
    Once this table get record, TRIGGER should call SHELL SCRIPT to move the files from common area to input area.
    If I implement ORACLE TRIGGER, The script which will check whether the file got updated or not for 15 mins is not required. Right? Inputs from experts are welcome!

    >
    But...I just thougt instead of writing a shell script to do the above one, Why shouldn't I capture the date in a table (New table needs to be created) and use ORACLE TRIGGER to run the shell script to move the files from common area to input file directory to process those files?
    >
    Triggers should not be used to do transactional work. There is no COMMIT in a trigger. What happens if the trigger runs the shell script and then a ROLLBACK occurs? You will have run the shell script when it shouldn't run.
    Create a stored procedure to run the shell script. Call the stored procedure when the partition is created.
    If you were using 11g and interval paritioning you wouldn't need to create the partitions manually. Oracle could create the partitions automatically.

  • Executing a shell script from java using runtime.exec()

    Hi I am trying to create a script (test_script) and execute it -- all within one java program...
    the code compiles and executes perfectly but nothing happens. This is probably because the script does not get changed to the '777' mode although i am trying to do that ... any suggestions ???
    //code
    import java.io.*;
    import java.util.*;
    public class ScriptBuilder
         public ScriptBuilder() {
         public void writeScript() throws java.io.IOException{
         FileWriter writer = new FileWriter(new File("test_script"));
              writer.write("#! /bin/sh\n");
              writer.write("cd prodiags\n");
              writer.write("tar cvf delTask.tar delTask\n");
              writer.write("rm -rf delTask\n");          
              writer.flush();
              writer.close();
    Runtime rt= Runtime.getRuntime();
    String[] cmd = new String[3];
    cmd[0] = "ls";
    cmd[1] = "chmod 777 test_script";
    cmd[2] = "./test_script";
    rt.exec(cmd);
         public static void main (String[] args)throws java.io.IOException
         ScriptBuilder sb = new ScriptBuilder();
         sb.writeScript();
    }

    I don't know exactly but the code written below is working fine try the same with your code .Even with your code instead running the code with
    " ./<filename> ",if you execute it with "sh <filename>" command without changing the mode of the file it is executing properly.
    import java.io.*;
    import java.util.*;
    public class ScriptBuilder
    public ScriptBuilder()
    public void writeScript() throws java.io.IOException
    FileWriter writer = new FileWriter(new File("test_script"));
    writer.write("#! /bin/sh\n");
    writer.write("ll>/home/faiyaz/javaprac/checkll");
    writer.flush();
    writer.close();
    Runtime rt= Runtime.getRuntime();
    rt.exec("chmod 777 test_script");
    rt.exec("./test_script");
    } public static void main (String[] args)throws java.io.IOException
    ScriptBuilder sb = new ScriptBuilder();
    sb.writeScript();
    }

  • Execute Shell Script from OWB Process Flow

    I am trying to execute a Shell Script from a User Defined activity of OWB Process Flow. As I have not done such things earlier
    I need to know:
    1. Where I will put the Shell Script (move_file.sh)?
    2. What are the values in need to enter in the external process parameters (such as Command, Script, Result Code, Parameter List, Sucess Threshold etc)
    Please reply this thread. It would be a big help for me and probably for others as well.
    Kind Regards
    Zakir
    Message was edited by:
    Zakir

    Check this out,.
    http://download-uk.oracle.com/docs/cd/B31080_01/doc/owb.102/b28223/ref_processflows.htm#i1173362
    And answer to your question1, the shell script should be on the unix server.
    Regards

  • Execution of Perl Script from HTML DB page.

    Hi All,
    I have a Perl script which takes 5 parameters and fetches data from one database and insert that data into my database table which is a master table for my project.
    Is there any way to execute the perl script from a HTMLDB page by passing parameters.
    Pls. provide me inputs if any.
    Thanks & Regds.
    Kumaraswamy RJ.

    Check out MOS note 1515609.1.
    Regards,
    - Loc

  • How to execucte/calll a shell script from oracle

    hi all
    i want to execute a shell script from oracle...... how do i do that can any one send me a good link which i can refer and learn
    or if any one has already implemented anything like this plz let me know the code
    Regards

    Here u goooooo
    http://www.experts-exchange.com/Database/Oracle/Q_21908413.html
    Regards,
    http://www.oracleracexpert.com
    Send email using UTL_MAIL in oracle.
    http://www.oracleracexpert.com/2009/11/send-email-using-utlmail-in-oracle-10g.html
    Migrate Non-ASM Database to ASM using RMAN
    http://www.oracleracexpert.com/2009/10/migrate-database-to-asm-using-rman.html]

Maybe you are looking for

  • How to delete the sales org information from BP Master Data in SAP CRM 5.0

    Hi Guruu2019s How to delete the sales org information from BP Master Data in SAP CRM 5.0 Thanks... Mahesh Pasupunuri

  • Position key flex filed not populating in Position Flexfiled Structure

    I have created a Position Key Flex field. While Creating Business Group Organization, Position key Flex Field is not populating in Position Flexfiled Structure Field. Work Structure > Organization > Description Org Classification : Business Group

  • Performance issue in APO Module

    Hi All, While running the Demand Planning Book in APO Module, (Transaction Code :: <b>/n sdp94</b>) with 150 users, we faced a huge performance issue in both (while doing screen navigation & saving data). The planning book volume was for about 250 pr

  • I see CS6 has the same out of memory errror as CS5

    I have used CS5 in the past and after a short while I always got an 'Out of Ram' error. (laptop has 4 GIG) I was hopeful CS6 woud be better but I just got the same error after only using it a short while...... shame still not fixed. Hope its fixed in

  • I'm getting an error "Security level is set to High..."

    When I'm trying to combine multiple Word documents into a single PDF I'm getting an error "Security level is set to High...". I regularly did this at my previous office, and the process involved dragging the Word doc's from an Explorer window into an