no message
parent
d3ae877447
commit
75bedd71b4
@ -1,138 +0,0 @@
|
||||
package cfs.schd;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import cfs.trsmrcv.dao.TrsmrcvDao;
|
||||
|
||||
@Component("customCommand")
|
||||
public class CustomCommand {
|
||||
|
||||
protected Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Resource(name="trsmrcvDao")
|
||||
private TrsmrcvDao trsmrcvDao;
|
||||
|
||||
public final String WORK_DIR = "/gpta/source-app/cfs/customCommand";
|
||||
|
||||
public void make(String commandName, String commandCn){
|
||||
String fileName = commandName+".json";
|
||||
|
||||
File file = new File(WORK_DIR+"/"+fileName);
|
||||
try {
|
||||
FileOutputStream fos = new FileOutputStream(file);
|
||||
fos.write(commandCn.getBytes());
|
||||
fos.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean shellCmd(String cmd) {
|
||||
Process process = null;
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
StringBuffer successOutput = new StringBuffer();
|
||||
StringBuffer errorOutput = new StringBuffer();
|
||||
BufferedReader successBufferReader = null;
|
||||
BufferedReader errorBufferReader = null;
|
||||
String msg = null;
|
||||
boolean result = false;
|
||||
|
||||
|
||||
List<String> cmdList = new ArrayList<String>();
|
||||
|
||||
cmdList.add("/bin/sh");
|
||||
cmdList.add("-c");
|
||||
|
||||
cmdList.add(cmd);
|
||||
String[] array = cmdList.toArray(new String[cmdList.size()]);
|
||||
|
||||
try {
|
||||
process = runtime.exec(array);
|
||||
successBufferReader = new BufferedReader(new InputStreamReader(process.getInputStream(), "UTF-8"));
|
||||
|
||||
while ((msg = successBufferReader.readLine()) != null) {
|
||||
successOutput.append(msg + System.getProperty("line.separator"));
|
||||
}
|
||||
|
||||
errorBufferReader = new BufferedReader(new InputStreamReader(process.getErrorStream(), "UTF-8"));
|
||||
while ((msg = errorBufferReader.readLine()) != null) {
|
||||
errorOutput.append(msg + System.getProperty("line.separator"));
|
||||
}
|
||||
|
||||
process.waitFor();
|
||||
if (process.exitValue() == 0) {
|
||||
result = true;
|
||||
} else {
|
||||
logger.info("abnormal finish error : " + successOutput.toString());
|
||||
}
|
||||
|
||||
if (errorOutput.toString().length() > 0) {
|
||||
logger.info("error : " + errorOutput.toString());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.info(e.getMessage());
|
||||
} catch (InterruptedException e) {
|
||||
logger.info(e.getMessage());
|
||||
} finally {
|
||||
try {
|
||||
process.destroy();
|
||||
if (successBufferReader != null) successBufferReader.close();
|
||||
if (errorBufferReader != null) errorBufferReader.close();
|
||||
|
||||
} catch (IOException e1) {
|
||||
logger.info(e1.getMessage());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void bringJuso(){
|
||||
|
||||
SimpleDateFormat sdf6 = (new SimpleDateFormat("yyyyMM"));
|
||||
Date now = new Date();
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(now);
|
||||
cal.add(Calendar.MONTH, -1);
|
||||
String targetYM = sdf6.format(cal.getTime());
|
||||
|
||||
String year = targetYM.substring(0, 4);
|
||||
String month = targetYM.substring(4);
|
||||
Map<String,String> searchMap = new HashMap<String,String>();
|
||||
searchMap.put("year", year);
|
||||
searchMap.put("month", month);
|
||||
String link = trsmrcvDao.getJusoDownLink(searchMap);
|
||||
|
||||
String customCommandName = "bringJuso";
|
||||
this.make(customCommandName,"{\"link\" : \""+ link +"\"}");
|
||||
|
||||
String line_of_shell = String.format("sh "
|
||||
+"/gpta/source-app/cfs/relay_jar/run_customSender.sh "
|
||||
+customCommandName+".json "
|
||||
+"/gpta/source-app/cfs/relay_jar/data/customCommand "
|
||||
+"/gpta/source-web/cfs/relay/data/customCommand "
|
||||
+"/home/tcs/customCommand "
|
||||
+"/home/tcs/customCommand "
|
||||
+"3ho");
|
||||
this.shellCmd(line_of_shell);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue