Using a UNIX shell script to run a Java program (packaged in a JAR)
Hi,
I have an application (very small) that connects to our database. It needs to run in our UNIX environment so I've been working on a shell script to set the class path and call the JAR file. I'm not making a lot of progress on my own. I've attached the KSH (korn shell script) file code.
Thanks in advance to anyone who knows how to set the class path and / or call the JAR file.
loggedinuser="$(whoami)"
CFG_DIR="`dirname $0`"
EXIT_STATUS=${SUCCESS}
export PATH=/opt/java1.3/bin:$PATH
OLDDIR="`pwd`"
cd $PLCS_ROOT_DIR
java -classpath $
EXIT_STATUS=$?
cd $OLDDIR
echo $EXIT_STATUS
exit $EXIT_STATUS
Hi,
I have an application (very small) that connects to
our database. It needs to run in our UNIX environment
so I've been working on a shell script to set the
class path and call the JAR file.
#!/bin/sh
exec /your/path/to/java -cp your:class:paths:here -MoreJvmOptionsHere your.package.and.YourClass "$@"Store this is a file of any name, e.g. yuckiduck, and then change the persmissions to executechmod a+x yuckiduckThe exec makes sure the shell used to run the script does not hang around until that java program finishes. While this is only a minor thing, it is nevertheless infinite waste, because it does use some resources but the return on that investment is 0.
CFG_DIR="`dirname $0`"You would like to fetch the directory of the installation out of $0. This breaks as soon as someone makes a (soft) link in some other directory to this script and calls it by its soft linked name. Your best bet if you don't know a lot of script programming is to hardcode CFG_DIR.
OLDDIR="`pwd`"
cd $PLCS_ROOT_DIRVery bad technique in UNIX. UNIX supports the notion of a "current directory". If your user calls this program in a certain directory, you should assume that (s)he does this on purpose. Making your application dependent on a start in a certain directory ignores the very helpful concept of 'current directory' and is therefore a bug.
cd $OLDDIRThis has no effect at all because it only affects the next two lines of code and nothing else. These two lines, however, don't depend on the current directory. In particular this (as the cd above) does not change the current directory for the interactive shell your user is working in.
echo $EXIT_STATUS
exit $EXIT_STATUSEchoing the exit status is an interesting idea, but if you don't do this for a very specific purpose, I recommend not to do this for the simple reason that no other UNIX program does it.
Harald.
Similar Messages
-
Schedule workbook using with Unix shell script
Hi,
Can we schedule workbook using with Unix shell script?
Thanks,
JayI can't imagine how.
1. You can schedule Disco workbooks via Disco itself.
2. You can schedule Disco workbooks to run and output in different file formats automatically via batch scheduler in Windows running Disco Desktop directly (or can user VBasic).
3. You can schedule Disco workbooks to run and output in different file formats automatically via a Java program running the Java Command Line interface.
Moving forward, Oracle has announced that with a further interfacing of Disco with XML Publisher, you'll be able to use Oracle Apps concurrent manager and scheduling. But that's coming supposedly at the end of this year.
And I think that's about it.
Russ -
To write a perl script for running a java program from cgi of web server
I have to write a perl script to call a java program(.exe).I want to run this file through the cgi of the web server.
java myprogram
can anyone help me to write a perl script??It depends on what the java program does. For example, does it parse HTTP headers from standard input, or what?
Are you sure it wouldn't be easier to turn the class into a servlet? etc.
Take a look at IPC::Open2 and IPC::Open3 though. You may need them. (That's just a guess.) -
Shell script to run PL/SQL Program
hai,
i have problem in returning values from PL/SQL procedyre back to Shell script which calls the procdure.can anyone please suggest a model shell script to handle this
ThankyouSQL> create or replace function disp_mess
2 return varchar2 is
3 begin
4 return('Hello World');
5 end;
6 /
Function created.
SQL> select disp_mess from dual;
DISP_MESS
Hello World
SQL> exit
Disconnected from Oracle8i Enterprise Edition Release 8.1.7.4.0 - Production
With the Partitioning option
JServer Release 8.1.7.4.0 - Production
$ cat disp_mess.sh
MESS=`sqlplus -s scott/tiger << !
set head off
set pages 0
select disp_mess from dual;
exit
! `
echo $MESS
$ disp_mess.sh
Hello World
$Paul -
Unix shell script to do a cold backup
i want to do a coldback using a unix shell script.
the db capacity is around 12 Tb
wen the backup is done i need to zip it too.at this moment i dont want to copy to the disk.
kindly help me regarding this
thanks in advance
NKi used something like this until recently:
#!/bin/bash
umask 0077
export ORACLE_HOME="/u01/app/oracle/product/10.2.0/webdb1"
export PATH="$ORACLE_HOME/bin:$PATH"
export NLS_LANG="AMERICAN_AMERICA.WE8ISO8859P1"
db="dbname"
pipe="export.pipe"
file="$db-`date "+%Y-%m-%d"`.dmp"
if [ ! -p $pipe ]; then
## could exist but not be a pipe
rm -f $pipe
mknod $pipe p || (echo "could not create pipe $pipe"; exit 1)
fi
gzip -c > $file.gz < $pipe &
exp system/****@$db FULL=Y CONSISTENT=Y FILE=$pipe DIRECT=Y GRANTS=Y
you could of course also use zip|bzip2|pbzip2 or whatever.
hth, rgds, armin walland -
Execute a unix shell script from forms9i
Hi ,
I would like to execute a unix shell script form a form when they pressed a button. The forms server is on Linux machine. I tried but when I pressed the button nothings happen. Could some one please help me how I could get working.
Is there is a way I could execute the unix shell script from PL/SQL proceudre or package.
Please some one help me.
BainYou would not expect to see anything happening because the
script cannot directly send output to the web form. However, you can get it to write output to a file and use web.show_document in the form after the host command to display the file and see the output. -
Run Unix command / Run Unix shell script from Forms9i
Hi,
I have a requirement to run Unix command and Unix shell scripts from Forms9i.
I know HOST command cannot be used directly. I also know we can create some JAVA stored procedure to perform the task, but I don't want to create any JAVA stored procedure as there are some security concerns.
Please point me towards any other way to achieve the same.
I would really appreciate your help.
Thanks,
KumarThere is no reason why HOST can't be used. This is what it is for. As for using Java, it is not a stored procedure that you would be using, it would be imported Java (imported into the form).
The best way to use the HOST command is to call a script (.sh) rather than calling a Unix command directly. This is because HOST will not pick up environment variables set at the system level. So the script would first need to set the necessary environment variables then call the desired commands. -
Running Unix Shell scripts through Java
How to run Unix shell scripts through Java program ?
Use:
Process p = Runtime.getRuntime().exec("sh script.sh");Then you can use:
p.getOutputStream and read the output of your program. -
I hope someone knows Unix better me. I created a shell script to run some ap comp sci classes, and whenever I want to run the script, I'm forced to type:
"./runMBS", while I want to just type "runMBS". Any suggestions will be nice.
ThanksIf you only type the name of a command (or script) the Unix shell only looks for those commands in the directories specified in the $PATH variable. If you provide a full or partial path to the command then the shell will run the command at that location... that's why including "./" in front of your shell script works... it tells the shell to run the command in the current directory (ie "./").
You can either:
- move your shell script to one of the directories specified in your $PATH variable
or
- add the directory containing your shell script to your $PATH
To modify the $PATH so that it includes the directory your script resides in use something like this in your .bash_profile:
<pre>
PATH=$PATH:/path/to/scriptdir
export PATH
</pre>
Although it's possible to include "./" in your PATH, it's not advisable and can present security problems. Read this explanation for more information.
Steve -
Sending email attachments using unix shell script
hi
I want to send report generated my spooled file as attachment using unix shell script.
Can somebody help me out ?
many thanksthanks a tonn it worked.
but i have another issue is it possible to add names in CC also ?
Also here is my code which spools the output of SP to a txt file. the File name is generated dynamically.
as shown below:
I need to send this generated file as attachement.
how do I do this? Here the shell script
=========================================================
#!/bin/sh
ORA_USER=scott
ORA_PWD=tiger
#Get the input parameter
if [ ! "$1" ]; then
STR="NULL"
else
STR="'"$1"'"
fi
#echo "exec pkg1($STR);"
#Connecting to oracle
sqlplus -s <<EOF
$ORA_USER/$[email protected]
---sql plus enviornment settings
set linesize 160
set pagesize 60
set serveroutput on size 1000000 for wra
set feedback off
set termout off
column dcol new_value mydate noprint
select to_char(sysdate,'YYYYMMDDHH24MISS') dcol from dual;
spool &mydate.report.txt
exec pkg1($STR);
spool off
EOF
exit
=========================================================
the file name will take sysdate as name so that every time a new file will be generated.
this file I need to send as attachment.
null -
Generate RMAN backup Script using unix shell script
Hello,
Could somebody give me a unix shell script that would generate RMAN script based on some user defined parameters in a config file.
e.g.
rman.conf
CHANNELS=4
USE_CATALOG=Y
DEVICE='sbt_tabe'
etc.,
many thanks,
kamYou can actually encapsulate the RMAN commands inside the shell script.
However if you really want to create a seperate RMAN script file, you can use the unix shell's "echo" command to write set variables to a file.
Thus, for example,
echo "rman target / catalog rman/rmanpassword@crcat" > RMAN_Script.rmn
echo "backup database plus archivelog" >> RMAN_Script.rmn
echo "backup archivelog all" >> RMAN_Script.rmn
creates RMAN_Script.rmn with 3 commands. -
Unix shell script run from pl/sql procedure
Hi Guru
I want to run unix shell script from pl/sql procedure. Actual I want to run it from developer 10g form.
Please guide me in this regards
Regards
JewelLook at the host or client_host builtins in the help
-
Exit status running java classpath in a unix shell script
I'm new to putting java into unix scripts. I have a java classpath running inside of a unix shell script. During my testing it will error with java.io.FileNotFoundException error, which I know why that is, but when I set in my unix shell script this to see the right exit status of success/fail, it always shows a 0 for success when that isn't really the case. Below is the two lines I have set to capture the exit status and just display that exit status for now.
notifycode=$?
echo $notifycode
I have these 2 lines above on a line right below my java command in my unix shell script. How can I get my unix shell script to show the right exit status if the java classpath command fails? Thanks for any help.That's Java code, it says "End this Java application and send return code 1 back to the shell". As for how the shell gets the return code from the application, that's a question about your shell and not about Java programming, no?
-
how to run 3 job(a,b,c) parallel in unix shells script and after will complete d will start and we have to handle the error also
032ee1bf-8007-4d76-930e-f77ec0dc7e54 wrote:
how to run 3 job(a,b,c) parallel in unix shells script and after will complete d will start and we have to handle the error also
Please don't overwhelm us with so many details!
Just off the top of my head ... as a general approach ... something like
nohup proca
nohup procb
nohup procc
while (some condition checking that all three procs are still running ... maybe a ps -ef |grep )
do
sleep 2
done
procd
But, we'd really need to know what it is you are really trying to accomplish, instead of your pre-conceived solution. -
Running SQLPLUS from UNIX shell script
I'm not sure if this is the right forum, but...
How can I execute a sql file from inside the UNIX shell script, logging on to Oracle w/o supplying a UID/pwd? Normally, we log into UNIX using our own logon, then sudo as another user to login to Oracle. Now, I'm trying to create a UNIX shell script, where I'm already sudo'd as the UserID that logs into Oracle. I've tried the following, but can't get it to work. I'm a UNIX scripting noob. Any ideas?
example:
#! /usr/bin/ksh
sqlplus / \@test.sql << EOF
exit;
EOFI'm a UNIX scripting noob.In which case I feel obligated to point you at William Robertson's excellent article Database Shellscripts Considered Harmful. Save yourself a world of pain.
Cheers, APC
Maybe you are looking for
-
Please give me flowchart for this code...
Writing a Java applet to communicate with a serial device attached to the Device Server is very straightforward. However, familiarity with Java programming and a Java compiler are required. As with any network application, open a communication channe
-
Considerations for changing the machine(computer) name
We would like to change the machine name(computer name) which is installed Essbase. What steps needed before doing so? I know that Hyperion Configuration using computer name instead of localhost for setup the whole environment. Thanks in advance, Rog
-
Is Business Objects Xcelsius one of the many business objects?
Hi! Good morning! Sorry for this newbie question. I wonder that Is Business Objects Xcelsius one of the many business objects? If so, where to find the complete list of all SAP BOBJ? Thanks!
-
TNS-12518: listener could not hand off client connection
We've recently upgraded to Oracle 9.2 (on Solaris 9) and are having intermittent problems. After being up several hours we approach around 250-300 active connections to the database. Then intermintantly all clients receive TNS-12518 errors or Error 0
-
When I purchase chips in "poker" app, i see message "Please contact ITunes support to complete this transaction".What I have to do?