Use java to run a shell script which called a crontab command at Unix
I was trying to write an automate function using Java, which needs to call a shell script containing a crontab commend. The shell works fine without that crontab commend, but once I add it, the program won't execute that crontab commend.
public void cron(){
try
Process proc = Runtime.getRuntime().exec("script1");
BufferedReader br = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line;
while ((line = br.readLine()) != null)
System.out.println(line);
int returnValue = proc.waitFor();
br.close();
} catch (Exception e){} //
script1:
#!/bin/sh
crontab cronfile
Can someone help me out for this? Thank you.
Try this....
Process p = Runtime.getRuntime().exec("sh");
java.io.BufferedWriter bw = new java.io.BufferedWriter(new java.io.OutputStreamWriter(p.getOutputStream()));
bw.write("script1");
bw.flush();
bw.close();
Similar Messages
-
Procedure to call shell script which invoke java program
Hi
I have requirement for a pl/sql procedure to invokes a shell script which calls java programs.
I was using DBMS_SCHEDULTER to invoke the shell , the shell is getting invoked but it is not executing the java programs.
appreciate your suggestions and advices .
param1=$1
param2=$2
#echo "First parameter is:"$1
#echo "Param1 is:"$param1
if [ $# -eq 1 ]; then
java -jar -Xmx512m abc.jar ${CONFIG_DIR} $param1
elif [ $# -eq 2 ]; then
java -jar -Xmx512m abc.jar ${CONFIG_DIR} $param1 $param2
fi
Regardsuser458361 wrote:
Hi
I have requirement for a pl/sql procedure to invokes a shell script which calls java programs.
I was using DBMS_SCHEDULTER to invoke the shell , the shell is getting invoked but it is not executing the java programs.
appreciate your suggestions and advices .
param1=$1
param2=$2
#echo "First parameter is:"$1
#echo "Param1 is:"$param1
if [ $# -eq 1 ]; then
java -jar -Xmx512m abc.jar ${CONFIG_DIR} $param1
elif [ $# -eq 2 ]; then
java -jar -Xmx512m abc.jar ${CONFIG_DIR} $param1 $param2
fi
RegardsYou are doing the equivalent of making THREE Left turns instead of a single Right turn
Most likely the shell environment is woefully lacking in needed details
add new line as below
param1=$1
param2=$2
/usr/bin/env | /usr/bin/sort -o /tmp/capture.log
# make sure above Fully Qualified Pathnames are correct for your system!
After you invoke script from PL/SQL post content of /tmp/capture.log back here -
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
senthilkumarThis 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 -
Running a shell script through java
Hi all,
I have a simple question here.
How can I run a shell script through java and put the text output into a string.
I'd be very grateful if you could show me sample code...
Have a great day,
PeshoRuntime.exec()
There are plenty of examples. Read the following before continuing, however, as it will save alot of headaches:
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html -
I have a file with passwd format.I made a script for this file that is working as I wanted it to work.I have a list of options and each time I give an option,the script is doing something(for example,if I press "b" it makes something and if I press "a" it makes something else).All the results are an output from the file.
My question is how can I create a GUI in java for this script.For example if I want the script to do what it would do if I pressed the "a" button on my keyboard,but not by pressing "a",but by choosing from a drop down list or some other graphical feature(by ticking a check box,clicking a button etc).Can I do this with java?
LazarosHi,
I understand you can create a Java Swing gui for a bash shell script which takes both complex input and writes output to the stdout & files, to be specific. Is that correct?
If yes, could you give a simple example. Say for the following shell script.
#!/bin/sh
printf "Enter input\n"
i=0
while [ $i -ne 1 ]; do
read $inputVar
if [ "$inputVar" == "y" ]; then
printf "You typed yes\n"
i=1
elif [ "$inputVar" == "y" ]; then
printf "you typed no\n"
i=1
else
printf "Enter a valid character\n"
i=0
fi
done
Could you also point to some URL's which might help? Googling for "Java Gui for shell script" returns this as the first page, others dont really help. Googling "GUI for shell script" returns all other gui toolkits for xes but thats not what I want. I want a cross platform (nixes, Win*, MacOS* ) gui for a shell script ( which I plan to run using cygwin etc).
TIA
Vinod -
Trouble in Unix calling a Java utility from another shell script
Hi,
I'm able to run a shell script (call it script B) in Unix which calls a Java utility. When I call script B from another script (script A) I get the error below. I have done much work to make sure the environment variables are the same.
java.util.zip.ZipException: error in opening zip f
ile
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:69)
at com.something.runtime.ZipFileApplicationSource.<init>(ZipFileApplicationSource.java:22)
at com.something.runtime.ZipFileRuntime.main(ZipFileRuntime.java:35
ANY HELP WOULD BE GREATLY APPRECIATED.
ThanksHere's my guess, if this doesn't work, post your scripts and maybe that will help.
When you run your script B, you said it works. I think the problem is that when you run script B, your shell and envirenment variables are set by the window you're working in. When you call script B from script A, it creates a new shell to run it and it doesn't run the files that are run when you start a terminal or a telnet(it won't run .cshrc, .kshrc or .login). Depending on what OS you're using, I think the default shell is sh for most of them. The first line of script B should be
#!/(your bin directory)/(shell you're using)
for me it's
#!/bin/tcsh
then you might want to run your startup file to set envirenment variables, paths, etc...
source (your user directory)/(the file name)
for me it's
source ~/.cshrc
Then if you need to set the environment variables in your script.
set CLASSPATH /usr/local/j2ee/bin.....
set PATH /bin:/xyz....
If that doesn't help post your scripts, or if I didn't explain it will enough, just ask. -
How I run a shell script from the scheduler on 10.2.0.2.0 ?
Hello Oracle People,
I'd like to run a shell script from the Scheduler in my 10g database.
Right now it is a simple shell script.
Eventually it will wrap RMAN commands to back up my DB.
I wrote a simple pl/sql script to create a job:
-- cr_job10.sql
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'my_backup_job',
job_type => 'EXECUTABLE',
job_action => '/h/oracle/scripts/tst.sh',
start_date => '06-SEP-07 5.33.00PM US/Pacific',
repeat_interval => 'FREQ=DAILY',
end_date => '08-SEP-07 4.00.00PM US/Pacific',
enabled => TRUE,
comments => 'My Backup Job');
END;
I see no errors when I run the above procedure.
I checked DBA_SCHEDULER_JOBS and the job is in there.
The scheduler, though, errors out with an error which I see in a trace file:
/h/oracle/admin/orcl/bdump/orcl_j000_22396.trc
Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - Production
With the Partitioning, OLAP and Data Mining options
ORACLE_HOME = /h/oracle/product/10r2
System name: SunOS
Node name: sol
Release: 5.10
Version: Generic_118855-14
Machine: i86pc
Instance name: orcl
Redo thread mounted by this instance: 1
Oracle process number: 15
Unix process pid: 22396, image: oracle@sol (J000)
*** ACTION NAME:(MY_BACKUP_JOB) 2007-09-06 17:33:00.175
*** MODULE NAME:(DBMS_SCHEDULER) 2007-09-06 17:33:00.175
*** SERVICE NAME:(SYS$USERS) 2007-09-06 17:33:00.175
*** CLIENT ID:() 2007-09-06 17:33:00.175
*** SESSION ID:(140.13520) 2007-09-06 17:33:00.175
*** 2007-09-06 17:33:00.175
ORA-12012: error on auto execute of job 53267
ORA-27369: job of type EXECUTABLE failed with exit code: 274662
I googled on this:
ORA-27369: job of type EXECUTABLE failed with exit code: 274662
Google returned only 1 hit.
There, I see some evidence that I need to configure something inside
of Oracle to run shell scripts from the scheduler, but possibly just
for machines running windows. I'm running Solaris.
Do any of you know what I need to configure inside of Oracle to
run shell scripts from the scheduler?
-OwenHello people,
I should have added this bit of information:
"The script runs fine from oracle's crontab."
"The script runs fine from a shell owned by oracle."
I'm getting responses telling me to check my env variables and permissions
which would be helpful to a UNIX novice.
I have a feeling that no one is using the scheduler to run RMAN scripts.
Tim Hall suggested I take a close look at these files:
$ORACLE_HOME/rdbms/admin/externaljob.ora
$ORACLE_HOME/bin/extJob
Currently I'm setup like this:
bash sol root /h/oracle/product/10r2/bin 31 #
bash sol root /h/oracle/product/10r2/bin 31 # ll $ORACLE_HOME/rdbms/admin/externaljob.ora
-rw-r--r-- 1 root dba 52 Sep 7 15:29 /h/oracle/product/10r2/rdbms/admin/externaljob.ora
bash sol root /h/oracle/product/10r2/bin 32 #
bash sol root /h/oracle/product/10r2/bin 32 # cat $ORACLE_HOME/rdbms/admin/externaljob.ora
# externaljob.ora
run_user = rman
run_group = rman
bash sol root /h/oracle/product/10r2/bin 33 #
bash sol root /h/oracle/product/10r2/bin 33 #
bash sol root /h/oracle/product/10r2/bin 33 #
bash sol root /h/oracle/product/10r2/bin 33 # ll $ORACLE_HOME/bin/ext*
-rwsr-x--- 1 rman dba 30388 Sep 21 2006 /h/oracle/product/10r2/bin/extjob*
-rwsr-x--- 1 rman dba 30392 Sep 21 2006 /h/oracle/product/10r2/bin/extjobo*
-rwsr-x--- 1 rman dba 34468 Sep 21 2006 /h/oracle/product/10r2/bin/extproc*
-rwxr-xr-x 1 oracle dba 300 Sep 21 2006 /h/oracle/product/10r2/bin/extusrupgrade*
bash sol root /h/oracle/product/10r2/bin 34 #
bash sol root /h/oracle/product/10r2/bin 34 #
bash sol root /h/oracle/product/10r2/bin 34 #
On my system, the user 'nobody' has no shell so I cannot use nobody.
I created a user named rman:
bash sol root /h/oracle/product/10r2/bin 34 #
bash sol root /h/oracle/product/10r2/bin 34 #
bash sol root /h/oracle/product/10r2/bin 34 # su - rman
Sun Microsystems Inc. SunOS 5.10 Generic January 2005
$
$ id
uid=220(rman) gid=220(rman)
$
$
$ date
Fri Sep 7 16:30:03 PDT 2007
$
$
Jared points out that rman needs access to extproc:
$ ls -la /h/oracle/product/10r2/bin/extproc
-rwsr-x--- 1 rman dba 34468 Sep 21 2006 /h/oracle/product/10r2/bin/extproc
$
$
Here is a demo of rman running his script:
bash sol root /h/oracle/product/10r2/bin 35 # su - rman
Sun Microsystems Inc. SunOS 5.10 Generic January 2005
$
$
$ ls
scripts
$
$
$ scripts/tst.sh
$
$
$ cat scripts/tst.sh
#! /bin/sh
/usr/bin/date > /tmp/tst.sh.out.txt 2>&1 &
exit 0
$
$
$ cat /tmp/tst.sh.out.txt
Fri Sep 7 16:31:23 PDT 2007
$
$ rm /tmp/tst.sh.out.txt
$
I am focused on this error:
ORA-27369: job of type EXECUTABLE failed with exit code: 274662
And I am focused on this exit code: 274662
What does 274662 mean?
If the Scheduler gives me an error like "274662" rather than some English,
it's obvious to me the Scheduler is a POS and I should not use it.
And of course,
If I cannot run RMAN from Oracle Scheduler, I'll use cron.
-Owen -
How do I run a shell script via AppleScript?
Seems obvious, "do shell script" but that doesn't work for me.
I have an Automator app which runs a shell script, I'd like to take that into an AppleScript. My AS doesn't run the shell script. Perhaps "do shell script' is expecting the script to be located elsewhere? The rest of my AS runs fine, but the shell script doesn't.
repeat with i from 1 to count of items in exportFolder
do shell script
"exiftool -overwrite_original -Photoshop:CopyrightFlag='True'"
done
end repeat
As I say this works within an Automator app, what changes do I need to make it work in AppleScript?
Thanks!Camelot wrote:
repeat with i from 1 to count of items in exportFolder
What is 'exportFolder'? Where is it defined?
Thanks, 'exportFolder' is defined earlier in the script. The purpose of the script - which is run from within Aperture - is to rename the selected images, export them (to the 'exportFolder'), reset the version name and, using ExifTool, add metadata which Aperture does not write to exported JPEGs.
I have a version of this which works in Automator but I couldn't see any clues there on setting the path to ExifTool.
Here's the full (modified) script. Currently it returns an error
Result:
error "No file specified" number 1
so I now need to understand if I can use 'exportFolder' (defined at the start) to tell Finder which folder to use.
-- Creating filenames by making Version Name from the IPTC Headline and Filename (with hypens where spaces exist). The Aperture Version Name is used to create the file's name on export. Once exported the Aperture Version Name is reset to its original.
tell application "System Events"
set exportFolder to (choose folder with prompt "Choose an export folder")
end tell
tell application "Aperture"
set theSel to (get selection)
if theSel is {} then
error "Please select an image or two!."
else
repeat with theImg in theSel
-- Creating a new Aperture Version Name which will become the exported file's filename.
tell theImg
set headline to (get value of IPTC tag "Headline" of theImg)
set AppleScript's text item delimiters to " "
set theTextItems to text items of headline
set AppleScript's text item delimiters to "-"
set headline to theTextItems as string
set AppleScript's text item delimiters to {""}
set objectName to (get value of IPTC tag "ObjectName" of theImg)
set newVersion to (headline & "-" & objectName) as string
set name of theImg to newVersion
end tell
end repeat
-- Exporting the files as JPEGs to chosen folder/Project Name using the Version Name as a filename
export theSel using export setting "JPEG - Original Size" to exportFolder
-- Resetting the Aperture Version Name back to filename using IPTC Title (which should be the file's filename without suffex).
repeat with theImg in theSel
tell theImg
set title to (get value of IPTC tag "ObjectName" of theImg)
set name of theImg to title
end tell
end repeat
end if
end tell
--Using ExifTool to set Photoshop Copyright Status etc
tell application "Finder" to set theFiles to files of exportFolder as alias list
repeat with eachFile in theFiles
do shell script "/usr/bin/exiftool -overwrite_original -Photoshop:CopyrightFlag='True' -Photoshop:URL='http://davidgordon.co.uk/'" & quoted form of POSIX path of eachFile
end repeat
display dialog "Done that!" with icon note buttons "OK" default button 1 giving up after 10 -
Secure login to remote UNIX host and run a shell script
Hi I am new to JAVA. I want to login to remote UNIX host from my application secure login (SSH) and run a shell script reside that remote host. Can any one let me know the way how to do it. If possible provide the code example.
Runtime.exec with an ssh command (not really recommended).
Much better, an SSH API (JSch, which needs JZlib, from http://www.jcraft.com/ is a good one). -
Problem with running Bash shell scripts
I am unable to run Bash shell scripts on the UNIX Terminal application.
This is the transcript from the Terminal application.
Zhi-Yang-Ongs-Computer:/Applications/MetaPost/metapost-1.102 zhiyangong$ ./test1.sh
dyld: Symbol not found: _BC
Referenced from: /usr/local/bin/bash
Expected in: /usr/lib/libSystem.B.dylib
Trace/BPT trap
Zhi-Yang-Ongs-Computer:/Applications/MetaPost/metapost-1.102 zhiyangong$
Is this a problem with the the default installation of the Bash shell? Can I install the Bash shell on my own? If so, how can I do that?
Also, how can I get the dynamic linker, dyld, to refer to the symbol "_BC"? What does this symbol "_BC" refer to?This was in your posted output:
/usr/local/bin/bash
You are NOT running the default bash, you are trying to run a private copy.
The default Mac OS X bash is located at
/bin/bash
Try the following:
/bin/bash ./test1.sh
Does that work?
What is the first line of your script? Is it:
#!/bin/bash
Or maybe
#!/usr/bin/env bash
/usr/bin/env would find the first bash in PATH . I find this most useful for finding perl on different systems, but sh, ksh, bash, zsh, csh, tcsh are all generally found in /bin so I do not bother using /usr/bin/env
And if you have
#!/usr/local/bin/bash
Then the person that wrote test1.sh choose to use something besides the default bash
Or maybe this script was transferred from some system where you needed to put your own copy of bash in /usr/local/bin because the vendor does not distribute bash
Then again, you have not showed us what is inside your script, so it is possible something in the script called something else which invoked the /usr/local/bin/bash
If that is the case, then you might try:
/bin/bash -x ./test1.sh
which should show you the commands executed before it died. -
How to run a shell script from the GUI?
This is probably a dumb question...
How do I run a shell script from the GUI? I've been told to double click it but when I do, it opens as a text file.The behavior you describe is that used by the KDE and GNOME desktops of Linux.
Under OS X, if you make a script then mark it as executable, double-clicking on it in the Finder will not execute it. Actually, it uses a rather complex algorithm ([summarized here|http://arstechnica.com/reviews/2q00/macos-qna/macos-x-qa-2.html]) to determine what to do with it. This is implemented in Mac OS X' LaunchServices framework (incidentally, the associations are cached in /Library/Caches/com.apple.LaunchServices*.csstore and ~/Library/Caches/com.apple/LaunchServices*.csstore). You can read the details in the developer docs about LaunchServices.
Anyway, in short, the suffix '.command' is a built-in type in the LaunchServices network that identifies a shell script. If you run
/System/Library/Frameworks/ApplicationServices.framework/Frameworks/LaunchServic es.framework/Support/lsregister -dump
... it will tell you as much. -
Hi,
Is there a way that we can run a shell script on UNIX box from ORACLE FORMS 4.5 running on client PC (OS=windows on client,
DB on unix).
Thanks in advance for help<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Anton Weindl ([email protected]):
You can either use rsh or rexec (both available on windows). You will have to edit the .rhosts in the home directory of the unix user the script will be run under:
<Client-Hostname> <USER>
<USER> must match the Windows-User exactly.
You can then execute the Shell-Script with
host('rsh <HOST> -l <USER> sh <SCRIPT>',NO_SCREEN)
Hope that helps
Anton Weindl
<HR></BLOCKQUOTE>
Thank You Anton Weindl,
It seems like the thing I want to use instead of the dbms_pipe.
I tried to use rsh and gives me the following message
command: "rsh taurus -l nileshs test.sh"
where taurus is hostname and
guest is unix username
I am logged on windows 2000 with this name.
"taurus permission denied:"
"rsh can't establish connection"
Let me know if I am missing anything.
Thanks.
null -
Do I run a shell script (bsh) via PL/SQL stored procedure?
Hello guys,
Do I run a shell script (bsh) via PL/SQL stored procedure?
For example:
procedure X is
(variables)
begin
-- Read file data
vFileHandle := utl_file.fopen('/mnt/novell/', 'file.txt','r');
exception
when 'INVALID READ FILE' then
(I've to try running script to mount a Novell partition.);
end;
I've to installed Oracle 9.0.1 on Suse Linux.
Please, any ideas or hints ...
Thx and regards.You might be able to us the HOST command, I think you'd have to run it via dbms_sql, check this page for more details, not sure if it'll be of help but its worth a try..
http://otn.oracle.com/docs/products/oracle8i/doc_library/817_doc/server.817/a82950/ch8.htm
Cheers
Rob -
Shell script to call sql script
Hi All,
I have a application server and want to make a shell script to call sql script.
Please let me know how to do the same.
Regards
KumarWhat is the platform you are using and you can give the path of the sql script in your shell script as follows
1.)first create .sql file...let it is table.sql and has the contents ...
create table test(x1 varchar2(20),x2 number(4),x3 date)
exit;
(2.) write a shell script...like table.sh in vi editor
Here login is scott/tiger@sid, or apps/apps@sid or whatever you know valid schema
echo enter the login
read login
sqlplus -s $login @table
(3.)run the script
$ sh table.sh
it will create the table in your particular schema -
How to run a java class from a shell script with passing arguments
hi,
I have a jar with all the required classes. I was using ant to run the classes i needed.
But now i want to use a shell script to run the class, also the class accepts some arguments so when script is run it should accept arguments.
So can any one tell me how to set class paths, jar location and call the required class from shell script or batch file with passing arguments to it.
Thanks in advance.Let's say that the order of arguments is as below
1. Jar file name
2. Classpath
Your shell script would look like this
java -cp $CLASSPATH:$2 -jar $1 I am assuming that your jar file has the required main-class entry in its manifest. Note that $1...$9 represent the arguments to this shell script.
The same goes for a batch file
java -cp %CLASSPATH%;%2 -jar %1
Maybe you are looking for
-
Exporting OS X Mail from Mountain Lion to Snow Leopard
After upgrading to Mountain Lion, I partitioned my iMac HD to have two partitions: Macintosh HD has Mountain Lion; I reinstalled Snow Leopard on Macintosh HD 2. Best part: you can access your user-created files from EITHER disk partition. But not so
-
Itunes doesn't see my iphone 5
Just got a new phone, but when I plug it into my MacBook Pro iTunes doesn't see it as a device. iPhoto launches, so it is not invisible. It's just iTunes that won't wake up. Help!
-
DB version:11.2 Platform : Solaris 10 We create RAC DBs manually. Below is a log of the DB creation from Node1 . Instance in Node2 is not yet created (only binary is installed in Node2). SQL> conn / as sysdba Connected to an idle instance. SQL> start
-
Can't use my car's bluetooth hands free set up when Bionic is synched
I don't know the tech jargon. I was able to pair my Bionic to my car's bluetooth hands free set up, but can't seem to use voice dialing. My car's display says that the phonebook has downloaded, and I can still take calls, but that's about it. It's
-
AirPrint problem finding the connection with macbook pro and macbook air for hp B110a
Recently my Hp B110a doesn't print out like normally. When I click print and it say 'no printer connection' I tried to turn off the wireless and set it up again and turn the printer on and off and still doesn't work. I have give up trying to make