Unix scripting in java

hello
im new to java.
and i need to learn unix scripting in java. is it difficult to learn? can one learn it within a short span of time?! could anyone please give me some links where i can learn.
tks

I run UNIX systems, what do you mean by Java scripting?
do you mean SH, BASH, TCSH, CSH shells and stuff? cause Java is platform independant?
btw, are you using Linux or FreeBSD?
p.s. Go FreeBSD!!

Similar Messages

  • Run a UNIX Script from java

    Hi,
    how can i run a unix script from java application. This java application is on windows.
    How can i do this.
    thanks,

    Hi,
    how can i run a unix script from java application.
    This java application is on windows.
    So I think it's safe to assume that the target script is on a remote unix server.
    Take a look at http://sourceforge.net/projects/sshtools/

  • Excute unix script from java.

    Hi need to excute unix script from java application.
    My code is:
    public class Test
    public static void main(String args[])
         try{
         p = Runtime.getRuntime().exec("./qfe0"); //qfe0 is the name of the script.
    p.waitFor();
    catch(Exception e)
    e.printStackTrace();
    My problem is that using the waitFor() statement stuck the the script. if i don't use the waitFor() it works good but then i don't know when the script is finished.
    Any idea?

    The problem is likely to be that you script is either waiting for input or has filled the stdout buffer and you are not emptying it. Search this forum for this as its been answered many times before.

  • How execute Unix script from java?

    Can I execute Unix script from java?

    Yes. Using ProcessBuilder. And read [When Runtime.exec() wont|http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html]. It's old, but pretty much all of it is still true.

  • Execute UNIX  script from java not working

    Hi
    I am having difficulty running my java program to execute UNIX script on a Windows box. Here is my code.
    public boolean executeScript() {
              try {
                   String testScript= "WEB-INF/scripts/test.sh";
                   File file = new File(copyToQaScript);
                   System.out.println(file.getAbsolutePath());
                   Process proc = Runtime.getRuntime().exec(file.getAbsolutePath());
              } catch (IOException ioe) {
                   ioe.printStackTrace();
                   logger.error(ioe);
              } catch (RuntimeException re) {
                   re.printStackTrace();
                   logger.error(re);
              } catch (Exception e) {
                   e.printStackTrace();
                   logger.error(e);
              return true;
         }When I execute this method, I am getting IOException as below.
    java.io.IOException: CreateProcess: C:\tomcat-5.0.28\webapps\myProject\WEB-INF\scripts\test.sh error=193
    Can anyone help me? Thanks.

    kminkeller wrote:
    Yes I have Cygwin installed. I am quite aware of that thanks Sabre.Then you need something like
          String[] command = {"bash","/home/sabre/bin/fred.sh"};
            Process p = Runtime.getRuntime().exec(command);
      if the executabe directory (/home/sabre/bin in my case) is not on the PATH or
          String[] command = {"bash","fred.sh"};
            Process p = Runtime.getRuntime().exec(command);
      if it is.

  • Problem executing Unix script from Java...

    Hi there, I'm having trouble executing a unix script from a java program. The script receives multiple parameters and it seems that one of them ( or more ) is not well interpreted. When I run the script directly from a shell, the script executes without any errors. But, when I run the exact same script with the exact same parameters, it does not work.
    Here is the command to execute the script with all the parameters that is executed from the shell ( with success ) and also from the java program ( with errors ):
    /z/opus/dcap/intfu001.csh 'NODEBUG^NOTKPROF^NOSTACK' opus dcap JACQUES JACQUES '2625781' 'ORA$PIPE$001D00D70001' JOB^DEBUG^SINISIMU^STATPROD^DECTIDANC^81^503^4080^86^87^151^97^98^99 BUT^N^N^SPRI^0^13^24^3^J^05^N^19^19^19 >> /tmp/switcher8.999.null.pgm.test
    And here is my portion of code that executes the script:
    Runtime wShell = Runtime.getRuntime();
    Process wProc = wShell.exec(cmd_unix_final);
    wProc.waitFor();
    return wProc.exitValue();
    Please give me your thoughts on this!
    Thanks in advance!

    Ok.
    Let's proceed surgically, else we'll never solve or overcome anything.
    In the last your reply you wrote:
    the normal output is what I get when the script runs successfully, the script first prints a few things
    and then does stuff that takes at least 2 or 3 secondsWhat do you mean?
    -Finally have you got your script correctly executed?
    The stuffs you spoke of are really performed?
    If this is the case I can't see the prob.
    Is your concern only about exitValue() for it doesn't let you distinguish programmatically
    the success or failure of the script execution?
    Of course you surely already have a routine in your java code to handle
    exceptional situations of errors from the script.
    And the "normal output" is just what you must parse to detect those errors.
    Then who cares about exitValue() in this case?
    Don't invoke it, relay on the stdout and stderr of the script.
    -Or you get only a deceiving standard output
    that let you think the script execution went alright, while instead it didn't.
    In this case we have to investigate some other thing.
    I can't still exclude that the problem isn't related with the buffer size of the stdout
    allocated by the environment to the subprocess. You spoke of few things printed out.
    Be explicit. What's the size of the output you get?
    And is the "normal output" complete till the very last char
    or is it truncated from somewhere on?
    Also it's important that you hit a ps command after the java main process terminates
    (or simply when waitFor() returns) and see if the script subprocess hung up.
    As an alternative approach directly call your pro*C code from Java through JNI, instead of translating it.
    1. Exec.java
    public class Exec{
         static{
              System.loadLibrary("Exec");
         public static native void proCFunct();
         public static void main( String[] args){
              proCFunct();
    }2. javac Exec.java
    3. javah Exec
    4.Exec.c
    #include "Exec.h"
    JNIEXPORT void JNICALL Java_Exec_proCFunct(JNIEnv * a, jclass b){
         //here call the function that executes the script
    5. cc -G -I$JAVA_HOME/include -I$JAVA_HOME/include/solaris -I$YOUR_INCLUDES Exec.c -o libExec.so
    6. setenv LD_LIBRARY_PATH .
    7. java Exec

  • How to Access UNIX scripts using Java

    folks,
    Is there any way we can access UNIX scripts or CRON Jobs in java, I am planning to come up with some monitoring tool for our application and in these i need to monitor the UNIX scripts whether its running or not ,
    Let me know if any of you guys done this,
    Regards
    Mathew

    Check the java.lang.Runtime object and exec(...) methods.
    Marc

  • Executing unix script within java and getting the return value

    Hi
    I am executing a unix script from within java which will return me a value. Is there a way I get this value and use it inside my java code without doing this:
    BufferedReader in = new BufferedReader( new InputStreamReader( ls_proc.getInputStream() ));
    //readLine reads in one line of text
    int k = 1, i = 0;
    while (( ls_str = in.readLine()) != null)
    --kirk123                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    I was hoping to get what I want in one or two line codes.
    --kirk123                                                                                                                                                                                           

  • Executing unix scripts from java...

    Hi guys,
    I'm pretty new at this java stuff, but can someone tell me if it's possible to have a java object that connects to a specific unix box through a given IP and Port and execute a Unix shell command? The shell script creates a file that will be later ftp'ed from the UX box back to the PC I ran the java program from. Any ideas?
    Thanks in advance.

    Yes I thank it can be done. I have not done it but you prob can do it through tcp/ip useing ServerSocket and socket class.Make a server with the ServerSocket class on the linux box that is listening to the port and when it gets the right signal from your client on your pc/win the server will activate the sell script with the Runtime.getRuntime().exec(shellscript);
    Well just a thought GOOD LUCK

  • How to execute unix script in java program that is on unix .

    hi ,
    I want to call "sendfax" script that is for sending fax to Hylafax server.
    This sendfax script is called in client java program.

    I want to call "sendfax" script that is for sending
    fax to Hylafax server.
    This sendfax script is called in client java program.And what is your problem?

  • Calling Unix-Script from within Oracle and store stdout/stderr in table

    Hi,
    What I want to do is:
    1. Calling a UNIX script (e.g. hello.sh) (from inside the Database)
    hello.sh
    echo “Hello World!“
    2. and get the stdout/stderr output back in my Database in a table (e.g. temp_back)
    table temp_back
    ID     stdout          stderr
    1     Hello World!
    I think Number 1 isn’t a big problem, but how to get stdout back in DB?
    Any solution?
    I searched a bit in this Forum and found this Post.
    re:Calling Host Command Through Database  Procedures or Triggers
    This may be what I am searching for, but can’t access the Link
    Since I am not really fit with UNIX and packages/procedures in Oracle it would be nice if you could post a very detailed answer.
    (Please no java)
    -What packages do I need? (heard DBMS_OUTPUT would be useful)
    -example PL/SQL script
    Thanks a lot!
    Marcus
    Environment:
    Oracle 9.2.0 DB

    Marcus, if you opened the Java sandbox to access any o/s file, you can call any Unix command, shell script, or program, that the Oracle o/s user has exec privs on.
    Just remember that there's a very basic Unix environment when you make the call - the settings in the .profile does not apply. Thus PATH for example is not set. When making the call make sure that the complete path is given. As for the environment, that is a problem as you cannot set that and make the call at the same time.
    In that case it is much simpler to rather write a Unix shell script that does all for you. Set the environment. Run the command(s). Format output. Etc.
    Then you call that Unix script, via Java, from SQL or PL/SQL. Treat the Unix scripts like the Unix-version of stored procedures for your Oracle application.
    Some technical details. When you connect to Oracle, a Unix process services you. This can be either a dedicated server process (servicing only your Oracle session) or a shared server process (from the shared service pool of processes).
    In either case, it is a Unix process running as a background process (thus detached from any tty device). PL/SQL and SQL are executed by this process. The Oracle JVM created by your session also lives in this process. When you therefore make o/s calls, these calls are made by this process.
    Therefore you are limited to what this process can and can't do. E.g. it runs as the oracle o/s user and will fail on accessing paths and commands does the oracle user does not have privs on. Etc.

  • 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();
    }

  • Looking for input on korn shell scripts to java programs

    I have a situation where there are several korn shell scripts and some manual processes using ms access to manipulate input files that will be used to pass to an applications command level commands for the purposes of updating the applications database. That being said, I am looking at creating the same as mentioned above in Java instead of ksh scripts. Mainly for the following reasons.
    The vendor is going web based, using a Java enabled web server, so these korn shell scripts if converted to Java could be called from the web jsp pages, etc.
    The other purpose is I see Java as a better tool for parsing the flat files and calling sql commands from the parsed data.
    I admit I am more a Java programmer than a korn shell programmer.
    What thoughts does this group have to using Java or should I polish my korn shell off a bit more?
    Thanks in advance
    Dean-O

    Hi,
    Is possible run Unix script under java application?, how?
    thanks

  • Running a Unix Script through a Java Program

    Hi !!!!!!!!! Can anybody plz suggest me an approach for the following queries -
    1.  How to execute a unix script through a java program ?
      2.  How to send the o/p of the script to a java program so that it can be used .

    import java.io.*;
    public RunScript
       public static void main(String args[])
          try
              Process p = Runtime.getRuntime().exec("script.sh");
              BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));     
              while ((line = input.readLine()) != null)
                 System.out.println(line);
              input.close();
          catch(Exception e)
              e.printStackTrace();

  • 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()

Maybe you are looking for

  • Over riding setting Delivery Content in 11g

    Hi, We migrated from 10g to 11g BP2. We are advised from our admins that we need to create 'Delivery content' in 'My accounts' sections as mentioned in http://www.biztech.com/blog/2012/10/setting-up-ibots-in-obiee-11-g/ 3. Setup the delivery option f

  • Update Other SLDs

    Hi, I have two NW 7.11 system. I want to transport technical and business system definitions from SLD to another's SLD. I have added the URL, username and password in Administration ->  data supplier/Update Other SLDs but it wasnt updated. What could

  • How can i integrate several transaction codes into a single report?

    Hi.. I am faced with a situation wherein i need to create a report. The output of the report is the combined output of the outputs of two or three standard sap transaction codes.. how can i code my report ? i tried to capture suitable portion of code

  • Can I transfer Elements tagging information to another computer?

    I have PS Elements 11 on my PC (Window 7) and now plan to run it on my PC laptop (Windows 7) Can the tagging information be transferred from the original PC to the laptop?  The PCs form a local network.

  • Highlighting current page on Tab control

    Hi!, I am using tab control with 7 pages. The page names are all in the same colour. Is there any way in which the colour for the name of the current page can be made different from the rest? If your answer involves property nodes (or more advanced t