Through a java prog how to execute a unix script ?

Hi !! I am a Java Developer . I have to work in Unix and Java in combination. Can you plz suggest me a solution for the below queries --
1. Through a java prog how to execute a unix script.
2. How to send the o/p of the script to a java prog so that it can be used in the java program to the prupose of display etc..

Try this
Process process = Runtime.getRuntime().exec("ps -ef");//write Your command here
               InputStream in = process.getInputStream();
               BufferedReader bufReader = new BufferedReader(new InputStreamReader(in));
               String data=null;
               while((data = bufReader.readLine())!=null)
                    System.out.println(data);   //do whatever you want to do with the output

Similar Messages

  • How to execute a sql script in dbms_job?

    how to execute a sql script in dbms_job?

    See my response to Re: how to execute a sql script file in procedure or trigger.
    Cheers, APC

  • How can i run unix script from my apex page

    how can i run unix script from my apex page and take the output of unix script as a hidden variable and display it on the report region of that page

    I had a requirement to run a Fortran program against some data that woudl be extracted from the database after the user set up their filtering criteria and made some additional input. SInce the program was to complex to conver to PL/SQL, we decided to try and invoke it from Apex. This is how I did it.
    1. I followed the steps in Tim Archer's excellent article "Oracle External Procedure to Run Host Commands" (http://www.timarcher.com/?q=node/9). If the link does nto work, google the article's title.
    Using this steps I created a function which accepts any OS command, including calling my own shell scripts, and runs them. I called my PL/SQL function "shell" instead of "USF_RUN_HOST_CMD " as Tim did in his example (step 9).
    2. In Apex,
    a. I created a button to run my shell command. (I named it P2_RUN_SHELL)
    b. I created a PL/SQL process whose source looks as follows:
    shell('/home/ackness/scripts/cr_xcf_file.sh > /tmp/cr_scfp_file.log');
    and which was conditioned on the the button P2_RUN_SHELL.
    It works like a charm.
    Note: since you can run your own scripts using this method, you can encapsulate a series of commands in a UNIX shell script and invoke that script from Apex. This allows you to be able to test or run you commands from the command line as well as Apex and makes it easier to develop/debug/enhance the scripts in the future.
    Ackness

  • How to execute a Unix Command in java

    Hi, Iam trying to execute a unix command on Sun Solaris by passing that command to a java program. How can I achieve this?
    Thanks in advance.

    Have a look at the javadoc around the Runtime.exec() method. If the command is a shell command then you might have to execute a shell as well as the command.
    For example, if you wanted to run a unix command 'ls -l > output.txt' the you might have to pass the following string into the exec() method,
    "/bin/sh ls -l > output.txt'

  • How to execute a unix/dos command in Java

    Hi,
    I want to execute dos/unix commands in my java program. Can anyone tell me how to do this. Say I want to restart my httpd daemon using the command: "service httpd restart" or test my httpd.conf file using the command "testparn"
    thanks in advance
    Hugo Hendriks

    hallo,
    test this:
    Process p = Runtime.getRuntime().exec(Your_Programm);
    p.waitFor();
    LineNumberReader lnr = new LineNumberReader(new InputStreamReader(p.getInputStream()));
    Your_Programm must be a shellscript. regard that your java programm must have the right to start the httpd!
    Carsten Bluetner

  • How to execute a SAP Script Configured in NACE as Output type?

    Hi all,
    I know the Outputtype. How to execute the Script? I have to modify the Script.
    Please help me.
    Thanx,
    Suresh

    After you have run TOAD and connected to Oracle DB, TOAD will open a "SQL Editor" window. If it does not, you can open it by clicking the "SQL" or "Editor" button in the tool bar.
    You can open the script in TOAD's SQL Editor Window like this:
    Press "Open File" button (yellow file icon) from the tool bar [ or from File menu, click "Open File" option]
    Navigate to directory where you script is residing
    select the script file and press "Open" button
    Now you can press the yellow 'bolt' button to execute your script.
    Once you have run the script successfully, click on the "Schema Browser" button [ which is next to the "Editor" button ]. In the schema browser's "Tables" tab, you can look for the table you have created.
    Alternately, you can also use SQLPlus to run your script either after launching SQLPlus and connecting to DB or from the command line.
    >
    i am not that much aware of toad .....
    >
    To get familiar with the tool, you'll have to explore it yourself if you plan to continue using it.
    NOTE
    You do not need "commit" after DDL statements. I noticed "commit" statements in your script. You can remove them.
    HTH

  • How to execute power shell script file inside DSC script resource

    Hi,
    How to execute /call powershell scirpt file inside DSC script resource , some thing like below and capture the status of execution.
    Node $AllNodes.NodeName
    Script ExecuteSQLDeploy
    #SetScript = {powershell.exe .\SQLDeploy.ps1  "param1" "param2" "param3" "param4" "param5" }
    #TestScript= {powershell.exe .\SQLDeploy.ps1  "param1" "param2" "param3" "param4" "param5 }
    #GetScript= { return $true;}
    Basawaraj

    Thanks for reply. 
     Now i am able to execute the power shell script with DSC. I  am getting no error when i run , but the script logic wrote inside  ( deploying sql incremental changes ) not working . I am using SQLCMD in the powershell script to deploy sql
    changes . Can you please elaborate on "script is compatible with DSC" , the script
    should not contain write-host cmdlet.... etc something like that.
    Copying recursively from ****************************** to ************************** succeeded.
    Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguration'.
    An LCM method call arrived from computer ************ with user sid **********************************************
    [V-BAKANT]: LCM:  [ Start  Set      ]
    [V-BAKANT]: LCM:  [ Start  Resource ]  [[Script]ExecuteSQLDeploy]
    [V-BAKANT]: LCM:  [ Start  Test     ]  [[Script]ExecuteSQLDeploy]
    [V-BAKANT]: LCM:  [ End    Test     ]  [[Script]ExecuteSQLDeploy]  in 0.1110 seconds.
    [V-BAKANT]: LCM:  [ Start  Set      ]  [[Script]ExecuteSQLDeploy]
    [V-BAKANT]: LCM:  [ End    Set      ]  [[Script]ExecuteSQLDeploy]  in 0.3010 seconds.
    [V-BAKANT]: LCM:  [ End    Resource ]  [[Script]ExecuteSQLDeploy]
    [V-BAKANT]: LCM:  [ End    Set      ]
    [V-BAKANT]: LCM:  [ End    Set      ]    in  0.8810 seconds.
    Operation 'Invoke CimMethod' complete.
    Time taken for configuration job to complete is 0.923 seconds
    Basawaraj

  • How to execute a shell script?

    Hi,
    could someone please tell me the correct way to execute a shell script? For example run.sh located in my resources?
    Thanx in advance!

    Odds are good that Apple doesn't want you running shell scripts on an iPhone, but somebody else might have information to the contrary.

  • How to run a unix script from oracle warehouse Builder

    Hi,
    can any one share the information about, running the unix script or scripts using oracle warehouse builder.
    Regards,
    Ak

    One way is define a workflow. Inside the workflow you put
    1)an external process that "points to" the shell script and then
    2)put the mapping
    The external process must have the "COMMAND" parameter set to the name of the shell script. If the script has parameters you must put them in the "PARAMETERS LIST" separated by "?" (for example, ?par1?par2).
    The path where OWB executes the external process I think is the ORACLE_HOME of the OWB.
    f you don't use workflow, you can try with this more complex solution. I tried with 9i and OWB 9.2 and it's working well.
    You create an autonomous procedure (within a package or not) :
    CREATE PROCEDURE Extract_Email_List
    DECLARE
    PRAGMA AUTONOMOUS_TRANSACTION;
    And use the sys.shell script that you need your dba/unix admin to install first of all, with a call like that.
    sys.shell('sh ' || txt_dir_name || '/send_email_marketing.sh ' || txt_dir_name || ' ' || email_addr );
    Then you import your procedure into OWB and use it in your mapping with the "pre-mapping" icon (you can set parameters for your proc with constants if you want).
    To implement sys.shell, go to metalink and find "Note:168065.1" - "How to call a UNIX shell script from PL/SQL".
    Once it's done once, it's not so bad. But I would still recommend the workflow approach also..
    I hope this helps.

  • How to invoke from UNIX script and pass back return code?

    Though I am an experienced developer, I am new to java. I created a class containing a single method. I have performed my testing by running the class class.method from the command line in a UNIX (Solaris) environment. Now, I would like to have the class.method invoked from a UNIX shell script, and to return a success/failure indicator from the method, to the UNIX script. I modified the method to make it return char, rather than being defined as void. Within the class and method, I declared and initialized a char variable. I added a finally clause which contains a single return statement, returning the char return code variable. Within my UNIX script, I invoke the class/method as follows:
    return_code = java myClass
    This does not seem to be invoking the method however. Can someone please tell me what I am doing wrong? Or is more information needed in order for someone to help me out.
    Please let me know.
    Thanks.
    Brad

    stdunbar,
    Using your suggestion of System.exit(retVal); seems to allow the java method to be performed successfully (Thank You). But I am still having a problem with the value being recognized by the shell script.
    In my script, I'm doing the following:
    java MyClass inputparameter > return_code
    export return_code
    echo $return_code
    But return_code does not seem to contain a value. Just before the System.exit(retVal); I added System.out.println("return code = " + retVal ); and I can see that retVal. When I run the java method outside of the UNIX shell script, I can see that retVal does indeed contain a value. So I think my problem might actually be the code in the UNIX script.
    Thanks again.
    Brad

  • How do I delete Unix scripts in /usr/local/bin/

    Well, I download a program call mpgtx (mpeg editor). After install, it put all its files to /usr/local/bin/, and there are unix scripts, mpgdemux, mpgcat..etc. So I just wander how I can delete them. Can just do rm mpg* from Terminal?
    Pls, help.

    I don't even HAVE a /usr/local/bin folder on either of my Leopard installs. One install does have a /usr/local folder, but everything in it was installed by the latest version of Privoxy, the other install doesn't have a /usr/local folder at all. So you won't mess up anything from the system. Whether you'll mess up some third party something or other you have installed only you can know. I suspect they probably don't take up much room, you could check that. If the amount of space consumed is trivial, you could just leave them.
    Francine
    Francine
    Schwieder

  • How to execute a .SQL script file?

    Hi
    I'm sure this question has been answered already, however I was unable to find an answer using the search tool.
    Using c# I'd like to run a .sql file. The sql file contains multiple sql statements, some of which are broken over multiple lines. I tried reading in the file and tried executing the file using ODP.NET ... however I don't think ExecuteNonQuery is really designed to do this.
    So I tried using sqlplus via spawning a process ... however unless I spawned the process with UseShellExecute set to true sqlplus would hang and never exit. Here's the code that DOESN'T WORK.
    Process p = new Process();
    p.StartInfo.UseShellExecute = false;
    p.StartInfo.RedirectStandardOutput = true;
    p.StartInfo.FileName = "sqlplus";
    p.StartInfo.Arguments = string.Format("xx/xx@{0} @{1}", in_database, s);
    p.StartInfo.CreateNoWindow = true;
    bool started = p.Start();
    p.WaitForExit();
    WaitForExit never returns .... Unless I set UseShellExecute to true. A side effect of UseShellExecute is that you can no capture the redirected output.
    This must be such a common thing to do, I'm hoping someone has a solution to this.
    Thanks
    Rich

    If by "SQL script" you mean run a program that resides outside the database (a file of the format whatever.sql) then the answer is with difficulty. We can use extproc calls to run c libraries or embedded java to execute host-style commands but it's a lot of pfaffing about.
    The easiest solution is to bring the SQL commands into the database as a stored procedure. If you still need to be able to run the script externally then rewrite that to call the same stored procedure. However, if the .SQL file includes OS calls then you will have to choose either Java or extproc, depending on what it is the script actuually does. If you want more focused advice you'll need to give us details.
    Cheers, APC

  • How to execute a shell script which is present in remote machine using ODI

    I have requirement of executing a batch (shell script) which is present in the remote machine.
    i have an ODI agent in remote machine as well. I have created agent locally by using the remote machine IP and port.
    I am able to test the agent successfully. But when i am executing the package using that agent it is failing with the following error
    errorODI-1226: Step Execution of the Scenario REMOTE_DEMO version 001 fails after 1 attempt(s).
    ODI-1241: Oracle Data Integrator tool execution fails.
    Caused By: oracle.odi.runtime.agent.invocation.InvocationException: HTTP/1.1 500 ODI-1423: Warning connecting to Agent localagent: work repository WORKREP1 is not bound to the master
    My Work Repository Name is : WORKREP1
    Remote Work Repository Name is:WORKREP_LOCAL.
    Could anyone please help me regarding this.
    I can't download shell script and run it locally this needs to be run on that remote machine only.
    Thanks
    senthilkumar

    This is the code.
    1. we can declare types dynamically
    2. Internal table dynamically
    3. Select querry dynamically
    just copy paste this code
    Here is the code for your question
    DATA:v_fieldname
    TYPE fieldname,
    l_PROG TYPE string,
    v_mess TYPE string,
    l_sid TYPE string,
    wa_ddfields TYPE dntab.
    DATA i_tab TYPE STANDARD TABLE OF string.
    DATA:l_str TYPE string,
    l_str1 TYPE string.
    PARAMETERS matnr type marc-matnr.
    end-of-SELECTION.
    *build the subroutine pool
    APPEND 'PROGRAM subpool.' TO i_tab.
    APPEND `LOAD-OF-PROGRAM.` TO i_tab.
    APPEND `DATA i_tab1 TYPE TABLE OF vbak.`      TO i_tab.
    APPEND `DATA l_rows TYPE i.`      TO i_tab.
    APPEND `select * into table i_tab1 from vbak.` To i_tab.
    append 'DESCRIBE TABLE i_tab1 LINES l_rows.' to i_tab.
    append 'Write :  l_rows .' to i_tab.
    GENERATE SUBROUTINE POOL i_tab NAME l_PROG
    MESSAGE v_mess
    SHORTDUMP-ID l_sid.
    IF sy-subrc = 0.
    PERFORM ('LOOP_AT_TAB') IN PROGRAM (l_PROG) IF FOUND.
    ELSEIF sy-subrc = 4.
    MESSAGE v_mess TYPE 'I'.
    ELSEIF sy-subrc = 8.
    MESSAGE l_sid TYPE 'I'.
    ENDIF.
    Edited by: vijay wankhade on Jan 1, 2009 5:34 PM
    Edited by: vijay wankhade on Jan 1, 2009 5:34 PM

  • Cannot Execute Any UNIX Scripts From DAC

    Hello,
    I have a BI system implementation on Oracle Solaris Servers. Both DAC as well as Informatica are on single server. My business requirement calls for a frequent Data load into BI and Cache purge. i checked the forum and found so many articles on how to automate Purging of Cache Post ETL. I am successful in creating a script to purge the cache and i already tested it by executing the script manually. But when i call this script from a DAC task it fails. In order to make sure that there is no problem with the Script i created a simple script which just says "Hello" and tried to invoke the script from DAC task but failed.
    All Task Batches
    External Program Batch
      EXTERNAL PROGRAM TASKTest:/PurgeCache/CachePurge.sh:(Source : FULL Target : FULL)
      2013-10-13 17:40:38.015 Acquiring Resources
      2013-10-13 17:40:38.015 Acquired Resources
      2013-10-13 17:40:38.015 EXTERNAL PROGRAM TASKTest:/PurgeCache/CachePurge.sh:(Source : FULL Target : FULL) has started.
      ANOMALY INFO::: Error while executing : EXTERNAL PROGRAM TASKTest:/PurgeCache/CachePurge.sh:(Source : FULL Target : FULL)
      MESSAGE:::com.siebel.analytics.etl.execution.exceptions.ExternalProcessException:
      EXCEPTION CLASS::: java.lang.RuntimeException
      com.siebel.analytics.etl.etltask.GenericTaskImpl.doExecuteWithRetries(GenericTaskImpl.java:536)
      com.siebel.analytics.etl.etltask.GenericTaskImpl.execute(GenericTaskImpl.java:372)
      com.siebel.analytics.etl.etltask.GenericTaskImpl.execute(GenericTaskImpl.java:253)
      com.siebel.analytics.etl.etltask.GenericTaskImpl.run(GenericTaskImpl.java:655)
      com.siebel.analytics.etl.taskmanager.XCallable.call(XCallable.java:63)
      java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
      java.util.concurrent.FutureTask.run(Unknown Source)
      java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
      java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
      java.util.concurrent.FutureTask.run(Unknown Source)
      java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      java.lang.Thread.run(Unknown Source)
      ::: CAUSE :::
      MESSAGE :::
      EXCEPTION CLASS::: com.siebel.analytics.etl.execution.exceptions.ExternalProcessException
      com.siebel.analytics.etl.etltask.ExternalProgramTask.doExecute(ExternalProgramTask.java:99)
      com.siebel.analytics.etl.etltask.GenericTaskImpl.doExecuteWithRetries(GenericTaskImpl.java:477)
      com.siebel.analytics.etl.etltask.GenericTaskImpl.execute(GenericTaskImpl.java:372)
      com.siebel.analytics.etl.etltask.GenericTaskImpl.execute(GenericTaskImpl.java:253)
      com.siebel.analytics.etl.etltask.GenericTaskImpl.run(GenericTaskImpl.java:655)
      com.siebel.analytics.etl.taskmanager.XCallable.call(XCallable.java:63)
      java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
      java.util.concurrent.FutureTask.run(Unknown Source)
      java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
      java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
      java.util.concurrent.FutureTask.run(Unknown Source)
      java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      java.lang.Thread.run(Unknown Source)
      (Number of retries : 1)
      /PurgeCache/CachePurge.sh
      2013-10-13 17:40:38.031 EXTERNAL PROGRAM TASKTest:/PurgeCache/CachePurge.sh:(Source : FULL Target : FULL) has finished execution with Failed status.
    (Failed)
    Any help would be greatly appreciated.
    thanks and regards,
    Sree

    See the thread below:
    Re: FDM - Script

  • How to run a Unix Script from a specific user

    Hi,
    I want to run a GoldenGate related unix script from a super user. I have created crontab enter from that super user. But its still running from root user. As GGSCI cannot be invoked other than super user, the Script is failing.
    The Script is running fine on command prompt and from "at" batch job command.
    Please give me a way to run the script from a specific user on Cron
    Thanks,
    Saravana

    Hi.
    can you show:
    grep root /etc/passwd
    grep <super user> /etc/passwd (It's not clear for me, what you call super user. For me - root is super user. )
    ls -la /var/spool/cron/crontabs
    Generaly for add cronjobs for any user need:
    crontab -e <username>
    For more information - man crontab
    Reagrds.

Maybe you are looking for

  • I cant access to database_homepage in localhost:8080. This requests user ps

    Hi, Ive a problem at the moment of open the database_homepage, the explorer says "The server localhost:8080 requires a username and password. Server Message: XDB." Ive Oracle Express Edition v11g release 2, but above I had Oracle Enterprise Edition,

  • I have the DAQ-6229 pinout sheet, but I need it to be defined.

    I am using the NI DAQ 6229 card.  I have a copy of the pinout off of the website, but I need to know what everything means.  Like,             PFI 11/P2.3, PFI 13 2.5, P0.5, AI 14, etc.  Any help you can give me will be appreciated greatly.

  • Upgrade to SBO 2007 : a user was added outside the application....

    Hi I just completed the upgrade of a system from 2005 to 2007. But when trying to create a new user, i've got this message : -> a user was added outside the application. Delete it, or perform "Restore Numbering" Do you have any idea on the way to ove

  • I have problem with serializable

    hello i recive de exeption "java.io.NotSerializableException: sun.awt.image.OffScreenImage" and i dont kwon why. if somebody can help me, thanks

  • Field is missing at the time of MD display

    Dear all Pl. go through with below mention point and give your suggestion User use to display the material document with T.code MIGO M.Type:- 201 Under WHERE tab system display the Text field (ie, on or before 15.12.2007) But after 15.12.2007 when ev