How to execute sh file of unix in java

iam trying to execute a sh file in target machine which will startup the database from source machine..
sh file is ..
# Synopsys
# This program startup's the database.
# Parameters
# @1: tuserconnect
# @2: tenvfile
# @3: tUserHome
progname=ajstartdb
echo "ssh ${1} . ${2} \&\& ${3}"
ssh ${1} . ${2} \&\& ${3}/ajss/sql/ajstrtdb.sh
retval=$?
echo "DEBUG::${progname}--> Completing execution with return code: $retval" > $progname.out
If i try to execute this ajstartdb.sh file in target itself it is executing perfectely.So i think no prob's with sh file..
but when i try to execute this sh file from java.. the process control is remaining in the prgm itself even after the cmd is executed.. i mean prgm is not exiting.
java prgm is :
import java.io.*;
class StartShut1
public static void main(String[] args)
try {
String cmd="ssh [email protected] . /d03/AppsGOLD/golddb/9.2.0/GOLD_hydapps.env \\&\\& /home/oragold/ajss/ajstrtdb.sh";
                         System.out.println(" the cmd is: "+cmd);
     Process p =Runtime.getRuntime().exec(cmd);
     int i = p.waitFor();
     System.out.println("Exit value of process is "+j);
                         System.out.println("Output of the Cmd is : "+i);
     String s=null;
     if (i!=0){
                              System.out.println("ERROR in executing the command");
                              BufferedReader cmdr = new BufferedReader(new InputStreamReader(p.getErrorStream()));
     while ((s = cmdr.readLine()) != null) {
                                             System.out.println(s);
                                                  s = null;
     BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
                                   // read the output from the command
                                   s=stdInput.readLine();
                         System.out.println(s);
     while (s!= null)
     System.out.println(s);
InputStream in = p.getInputStream();
int ch;
StringBuffer sb = new StringBuffer(512);
while ( ( ch = in.read() ) != -1 )
{ sb.append((char) ch); }
System.out.println("output from string buffer"+sb);
}catch(Exception e)
System.out.println("ERROR :"+e);
e.printStackTrace();
}//main
}//class
Kindly Reply me if u get an idea

And also u hv specified & in the cmd ... it is executing when we specify \&\& there.
Do u hv any idea ragarding this symbol (\&\&) in unix..Let us try first without vowels (the OP tends to drop them):
& n cmmnd prmpt wll trmnt th cmmnd nd rn t n th bckgrnd.
&& wll wrk lk n C (r Jv fr tht mttr): t wll vlt th frst trm nd g n xctng nd vltn
g f t ws "tr", tht s, f t yldd "zr" s rtrn cd.
For the faint the one with vowels:
& in a command prompt will terminate the command and run it in the background.
&& will work like in C (or Java for that matter): it will evalute the first term and go on executing and evaluating if it was "true", that is, if it yielded "zero" as return code.
Thus
posman@proli:~/ivan/fnt> test -d mydir && ls -l mydir
posman@proli:~/ivan/fnt> mkdir mydir
posman@proli:~/ivan/fnt> ls >mydir/1
posman@proli:~/ivan/fnt> test -d mydir && ls -l mydir
total 4
-rw-r--r--  1 posman users 522 Oct  4 12:24 1

Similar Messages

  • How to execute a file using jsp or java

    hi..
    i had a jsp file as front end with start and stop button,
    if i click the start button a file on my pc should execute.
    if stop button is clicked the file should stop execution.
    Any one know how to do this..especially how to run a file in ur system using java..
    Thanks in advance

    thanks for u r quick replies...
    Actually i want to run a file on a client machine
    only...
    Okay.
    for example, a client should execute a file which is
    in another client...
    This is not the same thing as what you just said.
    can u tell me the method to execute the file......java.lang.Runtime.exec

  • How to create pdf files in UNIX directory from oracle reports

    I would like to know how to create pdf files in UNIX directory from oracle reports.
    Thanks,

    Please make your question more clear . Also mention the reports version.
    1) If you are runnning reports in Unix, you can give
    .... destype=file desformat=pdf desname=<filename>
    in command line
    Please refer docs below.
    2) If by your question you mean
    "My reports server is running in Windows but I want to ftp my files to Unix after creating it"
    then the answer is that you can use pluggable destination "ftp"
    .... destype=ftp desformat=pdf desname=<ftp url>
    Pluggable destinations download
    http://otn.oracle.com/products/reports/pluginxchange/index.html
    Thanks
    Ratheesh
    [    All Docs     ]
    http://otn.oracle.com/documentation/reports.html
    [     Publishing reports to web  - 10G  ]
    http://download.oracle.com/docs/html/B10314_01/toc.htm (html)
    http://download.oracle.com/docs/pdf/B10314_01.pdf (pdf)
    [   Building reports  - 10G ]
    http://download.oracle.com/docs/pdf/B10602_01.pdf (pdf)
    http://download.oracle.com/docs/html/B10602_01/toc.htm (html)
    [   Forms Reports Integration whitepaper  9i ]
    http://otn.oracle.com/products/forms/pdf/frm9isrw9i.pdf

  • APEX: How to execute Script file from APEX

    Hello All,
    Can anyone tell me how to execute script file from APEX?(Step by Step process)
    Thanks & Regards,
    Jiten Pansara

    http://docs.oracle.com/cd/E23903_01/doc/doc.41/e21677/sql_rep.htm#AEUTL193
    Regards,

  • How to execute batch file from JSP

    hi frens !
    i wanna know how to execute batch file from my JSP.i am using exec() method to get call the batch file. but its not working ....plz help
    here mine code:-
    File F = new File("C:/var.bat");
         try{
          if (F.exists())
            Runtime rt = Runtime.getRuntime();
            String url=F.getAbsolutePath();
             Process proc = rt.exec(url);
            proc.waitFor();
            proc.destroy();
            catch(Exception IOEx){
           System.out.println(IOEx);
      }Thanks and Regards
    Allwyn

    You might improve your chances of getting help if you do two things:
    1) Explain what "not working" means.
    2) ChangeSystem.out.println(IOEx); to IOEx.printStackTrace(); (in the eventhat is in fact related to "not working").

  • How to execute a jsp instruction from a java class?

    How to execute a jsp instruction from a java class?
    Any help please.
    Thank's

    I'll detail my problem:
    Supposing that I have a jsp file called: start.jsp
    In the start.jsp I instanciated an object called global from the class Global ( for example ).
    Then, I called a custom taglib:
    <ix:mytag/>
    In the suitable tld file: the mytag is defined:
    <tag>
    <tag class>Tag1<.....
    The java file Tag1 has method:
    doStartTag(){
    // here is the problem
    global.doSomeFunctions();
    Okay, the problem is that the object gobal is not defined in the class Tag1. what to do?
    I think that I have to pass the object global as a parameter to the class Tag1. How to do that?
    Actually, the problem was to insert the follwoing in the doStartTag method:
    doStartTag(){
    pageContext.getOut().print("<%= hello world %>");
    The output is <%= hello world %> not hello world.
    Okay, the new problem is how to pass an object as a parameter to a class called from a tld file.
    Any help please.
    Thank's too much

  • How to extract .sit files(in MAC)  using java program

    Hi,
    please help me , i want to simple program for
    " how to extract .sit files(in MAC) using java program"
    that sit files same as zip files in windows..[                                                                                                                                                                                                                                                                                                                                   

    Thanks for reply...
    but i search in the google about this topic...there is no results will appear..
    the problem is "i have to run program in the MacOS like extract all the
    .sit(StuffIt) extension files. These sit files same as zip files in the windows... we have one tool called StuffIt Expander but it is 3rd party tool. but here requirement is i have to write my own program to extract all the files same as zip file program...
    please do the needful..i am waiting for ur reply,,,

  • How to write certain file On jCD through Java

    hi all,
    I got big problem in java , would anybody tell me how to write certain file onto CD through java. Is there any API available for this.
    Thanks in advance
    --Harish                                                                                                                                                                                                                                                                                                                                                               

    You might check this thread.
    http://forum.java.sun.com/thread.jspa?threadID=212748&tstart=90

  • Unable to locate existing  file from unix using java program

    Hi
    I have created a file in unix using java program, file.createNewFile();
    And when i try to search for the same file using file.exists() it is returning false. Paths are correct. Can anybody help me out.
    Thanks & Regards,
    Prasanth

    In Linux FC5 using JDK1.6, this code         File temp = new File(System.getProperty("user.home") + "/abcdefghijklmn");
            System.out.println(temp.createNewFile());prints 'true' and the file is created with length zero.

  • How to execute .sql file in Stored Procedure?

    Hi,
    I have an urgent requirement, where i have to execute .sql file form Stored Procedure.
    This .sql file will have set of update statement. I need to pass value to this update statement.
    Kindly please help me.
    Regards,
    Irfan

    This is required as part of Data Migration where  i have to do 100 of table's update. Each time update table will defer, so its better to have in separate script file (.sql). Can u paste some sample/syntax to exceute .sql file from stored procedure. I am new to this PL/SQL.
    How have you determined that it's "better" to have seperate scripts?  I assume you mean the table name will "differ" (and not "defer" - I assume that's just because English isn't your first language? no problem - I think I understand what you're asking).
    So what I think you're asking is that you have dynamic table names but each table needs to be updated in the same way?
    Question: Why do you have tables with different names that all need the same process doing to them?
    Assuming it's a valid requirement (and 99% of the time doing dynamic coding implies it's not).... you could use dynamic code, rather than 'scripts'...
    e.g.
    create procedure update_table(tbl_name varchar2) is
    begin
      execute immediate 'update '||tbl_name||' set lastupdate = null';
    end;
    As you haven't bothered to provide a database version, any example code/data or explanation of what you're actually doing, you're not going to get any detailed answer.  Please do take the time to read the FAQ and post appropriate details so people can help you.

  • How to RENAME the file in UNIX-Appl. server, after READING it?

    Hi Experts,
    Following is my requirement,
    What we are wanting here is the functionality added to this program that once the UNIX file is processed, that it can be closed and then renamed on the Application server with the yyyymmdd extension.  For example, the program reads and processes the My_file.csv file today.  Once it's finished, it then closes the file and renames it as My_file20080610.csv.  By doing this, it will prevent the same file from being run the next day in case the new file is not sent. 
    So, pls. let me know that, How to RENAME is file in the UNIX - Appl. server, after reading it? obviuosly I closes it at the end.
    thanq

    Hi Srinivas,
    You can create a My_file20080610.csv. Write the content from My_file.csv into My_file20080610.csv. Then using DELETE DATASET delete the file My_file.csv.
    Thanks
    Romit

  • How to execute jar file in java project

    hi,
    i have made a proj in java in which i have put all my files in a jar file.
    can somebody help me how to execute this jar file??
    thanks

    u can put that jar file in ur class path,,
    regards
    shanu

  • How to execute .msi files from java program

    Hi friends,
    i have written a java program which invokes and thereby execute any executable files like .exe and .bat.
    So its working fine with .exe and .bat files, but it is not working with .msi files.......can you please help me how can i execute .msi files as well??
    public class Executeexe {
         public static void main(String ar[])
              try
              Process p=null;
              Runtime rt=Runtime.getRuntime();
              p=rt.exec("D:\\mysql-essential-5.0.83-win32.msi");
              p.waitFor();
    catch(Exception e)
    }here is the program

    Make sure that the command that's being exec'd works from the cmd line.
    Then read this article and do what it says:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    Then if you still are having problems explain what "...it is not working with .msi files..." really means, and provide a [SSCCE Example program|http://mindprod.com/jgloss/sscce.html]

  • How to execute exe file from pl/sql

    How to execute an exe file or an operating system command from pl/sql in oracle 9i.

    If it is part of a pl/sql block, use the java suggestion. If you are not in a blck, you can use the "HOST" command. see
    http://download-west.oracle.com/docs/cd/A87860_01/doc/server.817/a82950/ch2.htm#1001697

  • How to write a file in unix server through oracle plsql code

    Hi All,
    My requirement is to create and write a file (any file for eg txt file) in unix box with in a specified directory through oracle plsql code.
    Oracle sits in windows server.
    using utl_file package we can create directory where oracle resides and write it there in oracle server in our case windows..
    But here we need to create,write a file but in unix server which is different server than where the oracle server resides..
    we are using Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    Can any one one please help me out in this issue...
    Thanks in Advance.
    Prakash

    Mr Prakash,
    Why are you asking this question multiple times in every forum you can spell?
    Valid responses have been presented to you already two times.
    Can you explain why you can't follow them up, but continue to abuse this forum by repeating doc questions?
    Sybrand Bakker
    Senior Oracle DBA

Maybe you are looking for

  • Screen layout

    Hi ALL, Where i can see screen layout for sales order document in IMG. I want to make sales group field Display mode only in sales order. Can it possible. If yes what is the path? regards, K.S.Rao

  • Will pay Spry Expert to fine tune vertical menu bar

    Hi, I have created a menu bar with DW CS4 for one of my web design clients, and I am running out of time to fine tune it. So I will pay an expert who can: 1. Reduce the font size to small (maybe 8pt) on all items because the client has way too many i

  • Territory Management - Looking for integration with ERP Cost Centers

    We are exploring using Territory management in CRM 7.0.  However, the hierarchy structure is really the same as our cost center structure in ERP.  The Business does not want to have to maintain this information twice.  Is there some way to update one

  • Auto calculation

    Hi, I have an issue regarding autocalculation.In report,Entity and Account dimensions are in row .Actual,budget,Variance and Variance% are the columns for that report.For entity, we have used base funtion.And auto calculation is on for entity.Now the

  • JWS doesn't launch after download an updated resource

    My application is launched correctly when I download the full application, but if JWS has to download an updated resource it stops the process when the resource is downloaded and my application is not launched. When it is done, I cancel the JWS dialo