private void jobRun(String jobCode, String time) throws Exception{
String cmd = null;
if(" ".equals(time)){
//直接启动
cmd = "sh " + jobpath + "/" + jobCode + ".sh";
}else {
// 定时启动
Long currentTime = getCurrentTimeMillis();
String day = dateAdd(currentTime, time);
// linux command
cmd = getCmd(jobCode, day);
}
Runtime run = Runtime.getRuntime();
Process proc = run.exec(cmd);
InputStream is1 = proc.getInputStream();
BufferedReader br1 = new BufferedReader(new InputStreamReader(is1, "MS932"));
String line;
while ((line = br1.readLine()) != null) {
logger.info(line);
}
InputStream is2 = proc.getErrorStream();
BufferedReader br2 = new BufferedReader(new InputStreamReader(is2, "MS932"));
String line2;
while ((line2 = br2.readLine()) != null) {
if (!line2.trim().equals("")) {
logger.info(line2);
}
}
br1.close();
br2.close();
int exitVal = proc.waitFor();
if (exitVal == 0) {
logger.info("COMMAND EXECUTION SUCCESSFUL: " + cmd);
} else {
logger.info("JOB PARM UNMATCH JOBNAME= " + cmd);
}
logger.info("----------------------------------");
}
private String getCmd(String key, String day) {
StringBuffer cmdStr = new StringBuffer();
cmdStr.append("at");
cmdStr.append(" -f ");
cmdStr.append(jobpath);
cmdStr.append("/");
cmdStr.append(key);
cmdStr.append(".sh");
cmdStr.append(" ");
cmdStr.append(day);
return cmdStr.toString();
}