Java and Shell Scripts

I have created a java program that its main target is to read from a log file. The GUI has six buttons and its button has a script running each time the button is being hit. The results of the script are presented on a JTextArea automatically. So I have six buttons and six scripts. The problem is that the first time the program works fine. But if I click one button for the second time I get no results or wrong results. The scripts alone(when they work without the java program) work right.
Is this a memory problem? How can I have the scripts with the java program work right together? I must say that each script needs 4-5 seconds to execute and immediately after the execution, the results, as I told before, are shown in a JTextArea. How can I solve the problem, so that I have the right results every time I click the buttons and not just for the first time?
I need your ideas as soon as possible. :)))
For connecting the java program and the shell scripts I use:
Process proc = Runtime.getRuntime().exec("bash script ");
OutputStream out = proc.getOutputStream();
PrintWriter p = new PrintWriter(out);
p.flush();     

I think u must use process.waitFor() method .
By this, u r sure that the said process shall complete.
Also I would recommend new Instance/Thread for running each script.

Similar Messages

  • Java and shell scripts - get password

    HI all,
    Im writing an installation prg using java appl on linux by running shell scripts. For this, I want to get root passwd in a text field from the user and use it in shell script (for cmd su) to get root login and to install my pkg.
    Can u help me to do this ???
    thanks in advance,
    rameshvl

    My only requirement is to install java (I have
    I have jdk rpm with me !!)
    with a user account. Hi ramesh,
    The discussion is now going a bit out of topic (this is a java forum).
    Unix Systems are multiuser systems. The users are organized to use the system concurrently. Therefore each user is able to write only in his area and in /tmp. If a user wants to install anything on this system he is able to do it in his area and not as root. root (the system administrator) is responsible for installing everything that is used by everybody. This means why do you have to start an application as user and then do something as root? Why don't you start the application as root and then be root to do everything you want?
    If you want the user to install java, why does he has to do this for everybody else on the system? Why not only install it in his home area? why the rpm, why not tar.gz?
    I hope this is a common reqmt of everybody, butNo this is not.
    I hope this helps
    M.

  • Rman windows and  Shell Script

    hi,
    How to take the backup by windows script and shell script.please any one tell that.
    thanks
    with regards

    Dear user!
    How to take the backup by script is a very imprecisely kind of question. So the only thing I can give you is a very imprecise answer.
    For linux shellscript you may use:
    vim my_backup_script.sh
    #!/bin/bash
    BACKUP DATABASE;Save and run this script in the following way:
    rman target / catalog catuser/password@CATDB CMDFILE my_backup_script.shYou may customize this script to fit your needs. On Windows you may write a batchscript like that:
    notepad my_backup_script.bat
    BACKUP DATABASE;Save and run this script like that:
    rman target / catalog catuser/password@CATDB CMDFILE my_backup_script.batMaybe if you could state your needs a little bit more precisely I could give you a more helpful answer.
    Yours sincerely
    Florian W.

  • Xgettext for perl and shell scripts on Solaris 9

    Hi......I have to internationalized perl and shell scripts on Linux and Solaris 9.
    I have used gettext on linux to internationalized both perl and shell scripts but on solaris i m not able to
    achieve the same.
    If we see help of xgettect on Linux, it shows input file options for Perl, Shell, C, C++ etc but help for
    xgettext on Solaris shows input file option for C only.
    Can you please provide me some way of using xgettext for perl and shell scripts on Solaris 9 or
    is there any other way of internationalizing perl and shell scripts on Solaris 9.
    Many Thanks,
    Lokesh

    Signature link blocked.
    db
    Contentprise wrote:
    Hi......I have to internationalized perl and shell scripts on Linux and Solaris 9.
    I have used gettext on linux to internationalized both perl and shell scripts but on solaris i m not able to
    achieve the same.
    If we see help of xgettect on Linux, it shows input file options for Perl, Shell, C, C++ etc but help for
    xgettext on Solaris shows input file option for C only.
    Can you please provide me some way of using xgettext for perl and shell scripts on Solaris 9 or
    is there any other way of internationalizing perl and shell scripts on Solaris 9.
    Many Thanks

  • BPEL processes and shell scripts

    Hi,
    I wish to invoke BPEL processes from a shell script so that it could be regulated from a typical Control-M environment. Can anybody let me know if its possible...?
    Regards,
    Roy

    Some kind-of Java interface would just be fantastic. Is there anything like that...?
    Well, I intend to execute some batch processes which would be scheduled and administered by Control-M; If i opt to use ws-clients within the same then auditing and monitering the status of my executing process would be an obvious overhead that i might need to hard wire in my implementation. Therefore, should it be possible to execute a BPEL process from a Java like interface, which i'd then wrap in a shell script; then Control-M on itself would be capable of monitoring the process status and all other performance parameters around the same.
    Suresh - Thanks for your suggestion, will definately post the message on those groups as well.

  • Java with Shell Scripts

    How can I include shell scripts in a java program?
    I want to create a GUI with Java and when I click a button or check a check box or choose something from a drop down list , I want a shell program to be called each time.For example, If i click a jbutton or check a jcheckbox, I want to execute something like this:
    sed 's/\([0-9]*\)\([-]\)\([0-9]*\)\([-]\)\([0-9]*\)\([-]\)\([0-9:.]*\)\(.*\)/\5\2\3\4\1\6\7/' $file >>temp;exit;;
    How can show the results on the GUI?
    All the graphical environment will be implemented with Java but underneath the job will be made by the scripts.
    I thank you in advance.
    I am looking forward to your answers.
    Lazaros

    Runtime#exec() returns a Process where you can call getInputStream().

  • Threads in java with Shell script

    hello
    I have shell script program which prints continuous number upto infinate.
    that shell script program is running or not i want to see by using threads in java can any one help me out.
    thanx
    mahen

    mark1971 wrote:
    You have to keep in mind that once a Thread finishes the run method you must not reuse it.Perfectly said. I believe sleep() can be replaced with wait() n notify(), if it is based on pre defined condition.
    For example, when input value read ( from kbd or socket etc) is "start", or time is between 2 pm and 3pm, this thread has to be executed.
    Once thread done its work, it can be again moved to wait() state.
    1. No need of stopping thread here.
    2. I think wait() may cause to latency.
    Please correct me if I am wrong.

  • Getting work done from java or shell script

    Hi,
    I have two programs one in java and other is as perl script or batch file. Java program does step 1 of work and perl script do the step 2. Step 2 run only when step completed successfully. And this both program run by script which is part of a big application. Can anybody suggest me if how to do this. Because we can not set environment variaables from a java code, I can not pass any thing to script which is running java and perl code. can any body suggest something.

    Your Java program could call System.exit(0) to end successfully and System.exit(1) if it failed. The shell script can look at the return code and act accordingly.

  • Error with dbms_scheduler and shell script execution

    Hi,guys.
    I have an issue with a dbms_scheduler and a shell script execution. So, the shell script as it self works fine, when i'm executing ./test.sh all process is running, but when i'm executing the script from dbms_scheduler it just simply doesn't work. Actually it works, but some of executable information in sh doesn't work, seems it just jump over of the part of the script. Sendmail part is running, maybe there is problem with rman script as it self?
    DB version: 10g
    And my scripts:
    Shell scripts (permisons 755):
    #!/bin/ksh
    export PATH=/home/oracle/product/asm_home/bin:/home/oracle/product/db_home/bin:/usr/bin:/etc:/usr/sbin:/usr/ucb:/home/oracle/bin:/usr/bin/X11:/sbin:.
    export ORACLE_BASE=/home/oracle/product
    export ORACLE_SID=zabbix
    export ORACLE_HOME=/home/oracle/product/db_home
    ${ORACLE_HOME}/bin/rman<<EOF
    connect target /
    run {backup recovery area delete all input;}
    EOF
    {       echo "From:[email protected]"
            echo "To: [email protected]"
            echo "Subject: Recovery area"
            echo 'Content-Type: text/html'
            echo
            echo '<html><body><table border="1" cellspacing="1">'
            echo '<tr><td><b>Process</b></td><td><b>Statuss</b></td></tr>'
            echo "<tr><td>RMAN</td><td><b>Works</b></td></tr>"
            echo "</table></body></html>"
    } | sendmail -tIn the first part i'm exporting all of the important stuff for oracle, then I call RMAN with specific atributes. And then there is just simply sendmail functionality inside script to represent if script works (for now).
    And below pl/sql script:
    begin
      DBMS_SCHEDULER.CREATE_JOB
      job_name => 'FLASH_RECOVERY',
      job_type => 'EXECUTABLE',
      job_action => '/home/oracle/backup/test.sh',
      start_date => sysdate,
      job_class => 'DEFAULT_JOB_CLASS',
      enabled => TRUE,
      auto_drop => FALSE,
      comments => 'FLASH RECOVERY USAGE AREA backup and delete'
      END;
      /And this job execution:
           begin
               DBMS_SCHEDULER.run_job (job_name =>'FLASH_RECOVERY',use_current_session => TRUE);
           end;What can be wrong? For me, I think it's something with permisions.
    I hope you got my idea and could help me.
    Tom
    Edited by: safazaurs on 2013.18.2 22:16

    There is no error, i just receive all the time e-mail, seems it jumps over rman. I tried almost everything and still couldn't get result as i want. And, if i'm running script from command line - it works. Rman calls, and starts to recover archivelogs.

  • SQL LOADER and SHELL SCRIPT ISSUE

    Hello Guys,
    I know this not the right forum but i am not sure where i should post this.
    Pelase help
    I am running a shell script which is giving me error
    Username:SQL*Loader-128: unable to begin a session
    ORA-01017: invalid username/password; logon denied
    SQL*Loader: Release 10.2.0.4.0 - Production on Thu Nov 19 13:02:04 2009
    Copyright (c) 1982, 2007, Oracle.  All rights reserved.
    SQL*Plus: Release 10.2.0.4.0 - Production on Thu Nov 19 13:02:06 2009
    Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.
    Enter user-name:
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL>
    0 rows updated.
    Commit complete.
    SQL> SQL> Disconnected from Oracle Database 10g Enterprise Edition
    SQL> SQL> Release 10.2.0.4.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options Thu Nov 19 13:02:06 EST 2009In shell script i have used the same username and passwd which i am using from command line
    the shell script is calling sql loader to load file
    and for that also the username and passwd is same.
    i am able to run sqlldr command from command line dont knw why here its giving error
    here is my shell script
    set -a
    . $HOME/.edw.env
    . $admlib/checklib.sh
    LOGDIR=$admsrc/sigma6/ppadala/copg
    LOGFILE=${LOGDIR}/log/test`date '+%m%d'`.xtr
    DB_USER=copg
    DB_PWD=copg
    set +a
    cd $LOGDIR
    if test ! -f $admsrc/sigma6/ppadala/copg/DM_Daily_EFolderCloseCancel_Report_11192009.txt
    then
       echo "Error: DM_Daily_EFolderCloseCancel_Report_11192009.txt does not exist and/or is not a regular file." >> ${LOGFILE}
       exit 1
    fi
    echo 'End of Checking for the existence of the file - Successful'>> ${LOGFILE}
    sqlldr control=$admsrc/sigma6/ppadala/copg/Close_Cancle.ctl log=$admsrc/sigma6/ppadala/copg/Close_cancle.log
    userid=${DB_USER}/${DB_PWD} silent=\(HEADER,FEEDBACK,DISCARDS\)>> ${LOGFILE} 2>&1
    case $? in 0) :;;1|3) echo "Error: SQL Loader" >> ${LOGFILE}
         exit 1;;
    esac
    sqlplus << EOD
    ${DB_USER}/${DB_PWD}
    @Close_Cancle.sql
    EOD
    if [ $? -ne 0 ]
    then
        echo "Error: SQL Plus for script Processing" >> ${LOGFILE}
        echo "Resi Unit Scheduling Report Refresh failed" >> ${LOGFILE}
    fi
    ) > ${LOGFILE} 2>&1
    echo `date` >> ${LOGFILE}
    if [ -f ${LOGFILE} ]
    then
    mail -s "Resi Unit Scheduling" "[email protected]" < ${LOGFILE}
    sleep 3
    `ck_error ${LOGFILE}`
    fiplease help guys
    thanks

    Thanks for the reply
    In Close_cancle.log also its the same msg which i posted.
    logon denied..............
    and this is the log file contents when i do set - X on
    + cd /u2144009/src/sigma6/ppadala/copg
    + test ! -f
    + /u2144009/src/sigma6/ppadala/copg/DM_Daily_EFolderCloseCancel_Report_1
    + 1192009.txt echo End of Checking for the existence of the file -
    + Successful
    + 1>> /u2144009/src/sigma6/ppadala/copg/log/test1119.xtr
    + sqlldr control=/u2144009/src/sigma6/ppadala/copg/Close_Cancle.ctl
    + log=/u2144009/src/sigma6/ppadala/copg/Close_cancle.log
    Username:SQL*Loader-128: unable to begin a session
    ORA-01017: invalid username/password; logon denied
    SQL*Loader: Release 10.2.0.4.0 - Production on Thu Nov 19 17:32:17 2009
    Copyright (c) 1982, 2007, Oracle.  All rights reserved.
    + userid=copg/copg silent=(HEADER,FEEDBACK,DISCARDS)
    + 1>> /u2144009/src/sigma6/ppadala/copg/log/test1119.xtr 2>& 1
    + :
    + sqlplus
    + 0<<
    copg/copg
    @Close_Cancle.sql
    SQL*Plus: Release 10.2.0.4.0 - Production on Thu Nov 19 17:32:58 2009
    Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.
    Enter user-name:
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL>
    0 rows updated.
    Commit complete.
    SQL> SQL> Disconnected from Oracle Database 10g Enterprise Edition
    SQL> SQL> Release 10.2.0.4.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    + [ 0 -ne 0 ]
    Thu Nov 19 17:32:59 EST 2009Edited by: user10647455 on Nov 19, 2009 2:35 PM

  • Command line parameters and Shell Script -- URGENT

    Hi folks,
    I am facing some problem in the Shell script and the command line parameter.
    The scenario is -- I am picking a file from a directory, whose path is <b>/interfaces/xid/receive/filename.dat</b>
    I have to encrypt filename.dat and move it to another folder, whose path is <b>/interfaces/xid/send</b>. So, the encrypted file will reside in the <b>send</b> directory.
    Now, I don't want to hardcode the new path, where the encrypted file has to be moved. Please let me know how to achieve this. Please consider this as urgent.
    Have a look at the command line in the "before message processing"  -- <b>/interfaces/xid/receive/xi_decompress.sh  /interfaces%F</b>
    Have a look at the shell script for the same --
    #!/bin/sh
    Setup environment variables
    COMMPRESS_DIR=/interfaces/software/commpress
    export COMMPRESS_DIR
    LOG_DIR=/interfaces/software/commpress/log/
    export LOG_DIR
    IN_FILE=$1
    export IN_FILE
    Find the directory where the unencrypted file is deposited
    IN_FILE_DIR=`dirname $1`
    export IN_FILE_DIR
    Make sure the working directory is where the unencrypt.key is...
    cd $COMMPRESS_DIR
    encrypt the file
    if [ `uname` = "HP-UX" ]
    then
       find $IN_FILE | $COMMPRESS_DIR/compx $IN_FILE_DIR logpath=$LOG_DIR
    else
       find $IN_FILE | $COMMPRESS_DIR/compx-sun $IN_FILE_DIR logpath=$LOG_DIR
    fi
    Get the result of the encryption
    RET_CODE=$?
    Check decryption result
    If error (retuen code <> 0), create an error log file in the
    same directory as the input file.
    if [ $RET_CODE -ne 0 ]
    then
        PREFIX="Decryption"
        DATE_TIME=$(date +%Y%m%d_%H%M%S%N)
        SUFFIX="err"
        FILENAME=$/$_$.$
        echo "Decryption Error log"        >$FILENAME
        echo "DATE_TIME:  $"   >>$FILENAME
        echo "DIRECTORY:  $" >>$FILENAME
        echo "FILE:       $"     >>$FILENAME
        echo "ERROR CODE: $"    >>$FILENAME
    fi
    exit $RET_CODE
    What else I need to add in this piece of code? Urgent help !!
    Thanks a lot in advance.
    Neetesh

    Hi Satish,
    I was able to figure that out, that we need to hard code the path as the 2nd parameter.
    But I guess there is a way out in Unix where we can handle this situation, where we are not willing to hard code.
    Anyways, thanks a lot for your input .. -:)
    Cheers,
    Neetesh

  • DBMS_SCHEDULER and Shell Script on 10.2.0.1

    Hi All
    My env, Oracle 10.2.0.1 and OS is Solaris.
    My script can run on OS that is work without error that contain create file, delete file, call sqlplus, function to get value from database and return to OS variables.
    In shell script some code as below
    get_val () {
    sqlplus -s /nolog <<EOF
    conn test/test
    set heading off
    set feedback off
    set pages 0
    SELECT SUBSTR (SYS_CONNECT_BY_PATH (Z, ' '), 2) z
          FROM (SELECT NAMEDQUERY , ROW_NUMBER () OVER (ORDER BY Z) rn,
                       COUNT (*) OVER () cnt
                  FROM X
                  WHERE Z LIKE '%FULL')
         WHERE rn = cnt
    START WITH rn = 1
    CONNECT BY rn = PRIOR rn + 1;
    EOF
    vx=$(get_val)
    if [ ${#vx} -gt 0 ]; then
    for xfile in $vx
    do
    rm -f $CURRDIR/$xfile.txt 2> /dev/null
    done
    fi
    When run by dbms_scheduler that show below error
    ORA-27369: job of type EXECUTABLE failed with exit code: No such file or directory
    STANDARD_ERROR="/home/oracle/script/test.sh: syntax error at line 26: `vx=$' unexpected
    How to resolve above error?  (owner of $CURRDIR/$xfile.txt is oracle user)
    One more question, How to force dbms_scheduler that using user oracle (OS) to run shell script?, as I know, default user is nobody and Oracle version 10.2.0.2 later that have external.job.ora to set it but 10.2.0.1 doesn't have it.
    Thank you in advance,
    Hiko

    I changed scheduler by set argument as below
    dbms_scheduler.create_job (job_name=>'TEST',job_type=>'EXECUTABLE',job_action=>'/usr/bin/bash',number_of_arguments=>1);
    dbms_scheduler.set_job_argument_value('TEST',1,argument_value,'/home/oracle/test.sh');
    That is work. below is conclusion to did
    1. Change permission of $ORACLE_HOME/bin/extjob to 4750 (-rwsr-x---)
    2. Change owner of $ORACLE_HOME/bin/extjob to oracle:dba
    3. Use '/usr/bin/bash' instead of '/usr/bin/sh'
    But I found error about download file process that I'm using wget to download source file in shell script and run by dbms_scheduler as above.
    My problem, first file can download normally and process until finish but second file was hang.
    Do you have any idea or solution to prove and resolve it?
    Thank you,
    Hiko

  • File locking and shell script

    Hi,
    with Mac OS X is there a file locking system to prevent file to be copyied or move to a folder B before they are completely copyied in folder A ?
    Regards

    The files in folder A are created by a program like
    Pitstop
    My question was : what can happen if a file in folder
    A is not complitely created and the shell script
    attempt to copy it ?
    In general, if the shell script attempts to copy a file before the creator is finished writing to it, the shell script will copy the part of the file that's already present, so the copy will be incomplete. The creating application can prevent that (by writing to a temporary file and changing the name of the file only after it's finished writing, or by making the file readable only after it's done), but that's up to the application.

  • Mount script for ext2 - mixing applescript and shell script

    Hello
    i want to do a .app using the ScriptEditor to get my external usb-disc mounted.
    I tried ExtFS Manager before, but was not as happy with it.
    so the basic idea is some kind of mixture of apple script and bash-shell script, but im not sure how to combine it.
    shell script:
    #!/bin/sh
    sudo kextload /Library/Extensions/ext2fs.kext
    mkdir ~/usb_music/
    sudo mount -t ext2 -o nosuid,w,m=777,user /dev/disk1s5 ~/usb_music/
    sudo chmod a+rwx ~/usb_music/
    apple-script:
    on run
    try
    do shell script ""
    end try
    end run
    any ideas how to get it combined and working ?
    best regards
    fidel
    MacBookPro 15,4" 1,83 GHz   Mac OS X (10.4.8)  

    is there a way to implement it in a way that normal users can work with sudo to mount the drive ?
    kextload requires superuser privileges, so at some point some part of your script is going to need to run with elevated privileges.
    It is possible to configure sudo to allow non-admins to run any other commands. You could either allow non-admins to to run kextload or, preferably, allow them to run your shell script.
    man sudoers will give you the details on how to configure sudo to do this, which might be as simple as:
    <pre class=command>ALL  ALL=(ALL) /usr/local/bin/myscript</pre>
    This will allow all users to run /usr/local/bin/myscript as root.

  • Sample shell script - to run procedures and shell script

    Hi ,
    I would like run some procedures in one shell script which passing parameters as username/password@dbname.
    1. Execute proce1
    2.Execute proce3
    3.Execute proc4
    Can you please give some script/idea how we will create shell script . I am using SunSolaris Unix operating system.I would appreciate your help.
    Regards,
    Clark

    user10818198 wrote:
    I would like run some procedures in one shell script which passing parameters as username/password@dbname.
    1. Execute proce1
    2.Execute proce3
    3.Execute proc4
    At a very basic level, based on the information you have provided, your shell script would be something like this:
    sqlplus /nolog <<EOF
    connect username/password@dbname
    exec proce1;
    exec proce2;
    exec proce3;
    exit
    EOFBesides this, you could:
    (1) Add the shebang at the top, to specify the shell you are using, e.g. #!/bin/ksh for the Korn shell etc.
    (2) Ensure that "sqlplus" is recognized by the shell, by maybe running an "ora_env.sh" script that sets Oracle parameters. More likely, if you are using this Unix account for interaction with Oracle, then you may want to add the Oracle parameter information in your .profile or .bash_profile or .csh_profile etc. in the home directory.
    (3) Run a few sqlplus commands right before calling those stored procedures, if needed. For example, if you want to exit from sqlplus (and Oracle) if an error occurs while executing any procedure, then add this -
    whenever sqlerror exit 1Thus your script becomes:
    #!/bin/ksh
    # Ensure that Oracle parameters are set by this point
    sqlplus /nolog <<EOF
    connect username/password@dbname
    whenever sqlerror exit 1
    exec proce1;
    exec proce2;
    exec proce3;
    exit
    EOF(There are other settings as well; it really depends on your requirements.)
    Can you please give some script/idea how we will create shell script . I am using SunSolaris Unix operating system.
    How to create a shell script ? Well,
    (1) Save the commands shown above in a file, using your favorite text editor. Name the file "my_script.sh" or "<a_better_name>.sh" etc. (or maybe ".ksh" for the Korn shell - it's just a best practice, the shell doesn't really care.)
    (2) Make your script executable, like so -
    $ chmod 744 myscript.sh(3) And then execute it -
    $ ./myscript.sh- You could also execute the script in the current shell (as against a child shell) by doing this after Step (1):
    $ . myscript.shHope that helps.
    If there are specific questions, then post them here.
    isotope

Maybe you are looking for