Oralce通过Java调用Shell 无响应
本帖最后由 loomz 于 2014-02-25 18:52:24 编辑
各位好:
我目前在做一个程序,Oracle存储过程通过Java(Java Sources)调用Shell脚本,试好其它方法,都没有成功。下面是我用通过java调用shell的代码:
create or replace and compile java source named execshellcmd as
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
public class execshellcmd {
public static String callShell(String path) {
String message = "";
try {
Process process = Runtime.getRuntime().exec(path);
int waitFor = process.waitFor();
InputStream is = process.getErrorStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line = null;
while ((line = br.readLine()) != null) {
message += line;
}
message += " Process waitFor=" + waitFor;
int exitValue = process.exitValue();
message += " Process exitValue=" + exitValue;
} catch (Exception e) {
message = e.getMessage();
e.printStackTrace();
}
return message;
}
}
包
create or replace package body PKG_EXECSHELLCMD is
FUNCTION callShell(PATH VARCHAR2) RETURN VARCHAR2 AS
LANGUAGE JAVA NAME 'execshellcmd.callShell(
java.lang.String)
return java.lang.String';
end PKG_EXECSHELLCMD;
job_ubs_ct.sh
#!/bin/bash
JOB_NO="UBS_CT"
logpath="/home/oracle/bip_job/"
logspath="/home/oracle/bip_job/logs/"
#logfile=`tr '[A-Z]' '[a-z]' <<
logfile="job_ubs_ct.log"
#curtime=`date '+%Y%m%d%H%M%S'`
#curtime="$(date -u +'%Y%m%d%H%M%S')"
curtime="20140225161111"
if [ ! -f "$logpath$logfile" ]; then
echo $curtime
else
#mv "$logpath$logfile" "$logspath$curtime$logfile"
echo $curtime
fi
echo "job start..."
nohup ./job_call_extract_data.sh $JOB_NO G010 >> $logfile 2>&1 &
nohup ./job_call_extract_data.sh $JOB_NO G020 >> $logfile 2>&1 &
nohup ./job_call_extract_data.sh $JOB_NO G030 >> $logfile 2>&1 &
nohup ./job_call_extract_data.sh $JOB_NO G040 >> $logfile 2>&1 &
nohup ./job_call_extract_data.sh $JOB_NO G050 >> $logfile 2>&1 &
nohup ./job_call_extract_data.sh $JOB_NO G060 >> $logfile 2>&1 &
nohup ./job_call_extract_data.sh $JOB_NO G070 >> $logfile 2>&1 &
nohup ./job_call_extract_data.sh $JOB_NO G080 >> $logfile 2>&1 &
nohup ./job_call_extract_data.sh $JOB_NO G090 >> $logfile 2>&1 &
nohup ./job_call_extract_data.sh $JOB_NO G100 >> $logfile 2>&1 &
nohup ./job_call_extract_data.sh $JOB_NO G110 >> $logfile 2>&1 &
nohup ./job_call_extract_data.sh $JOB_NO G120 >> $logfile 2>&1 &
nohup ./job_call_extract_data.sh $JOB_NO G130 >> $logfile 2>&1 &
nohup ./job_call_extract_data.sh $JOB_NO G140 >> $logfile 2>&1 &
nohup ./job_call_extract_data.sh $JOB_NO G150 >> $logfile 2>&1 &
nohup ./job_call_extract_data.sh $JOB_NO G160 >> $logfile 2>&1 &
nohup ./job_call_extract_data.sh $JOB_NO G170 >> $logfile 2>&1 &
nohup ./job_call_extract_data.sh $JOB_NO G180 >> $logfile 2>&1 &
nohup ./job_call_extract_data.sh $JOB_NO G190 >> $logfile 2>&1 &
nohup ./job_call_extract_data.sh $JOB_NO G200 >> $logfile 2>&1 &
job_call_extract_data.sh
nohup ./job_call_extract_data.sh $JOB_NO G200 >> $logfile 2>&1 &