본문 바로가기
IT 이모저모

[webMethods] 자바 서비스로 log파일 삭제하기

by DSEM 2021. 2. 10.
728x90
728x90

[webMethods 자바 서비스로 log파일 삭제하기]

find ./ -type f -mtime +90 -name * -exec rm -rf {} ;


webMethods 자바 구현한 후 실행해보면 실제 로그파일들이 삭제된 것을 확인할 수 있다.

IDataCursor pipelineCursorInput = pipeline.getCursor();
String[] dirList = IDataUtil.getStringArray( pipelineCursorInput, "dirList");  //삭제할 로그 디렉토리
String interval = IDataUtil.getString( pipelineCursorInput, "interval" ); //interval 이전 데이타
String fileLevel = IDataUtil.getString( pipelineCursorInput, "fileLevel" ); //파일별 삭제 여부
 
String filePattern = "*";
if(fileLevel.equals("true")) {
    filePattern = IDataUtil.getString( pipelineCursorInput, "filePattern" ); //파일 및 파일패턴
}
pipelineCursorInput.destroy();
 
//String dirHome = System.getProperty("user.dir"); //삭제할 로그 디렉토리
//String interval = "+60"; //60일 이전 데이타
String message = "Error";
 
try {
Runtime runtime = Runtime.getRuntime();
 
    if(fileLevel.equals("true")) {
 
        for(int i=0; i<dirList.length; i++) {
            runtime.exec"find " + dirList[i] + " -type f -mtime " + interval + " -name " + filePattern + " -exec rm -rf {};"))
            Thread.sleep(1000);
        }



    } else {
 
        for(int i=0; i<dirList.length; i++) {
            runtime.exec"find " + dirList[i] + " -type f -mtime " + interval + " -exec rm -rf {} ;"))
            Thread.sleep(1000);
    }
 
    }
    message = "Success";
 
catch(Exception e) {
 
}
 
IDataCursor pipelineOutput = pipeline.getCursor();
pipelineOutput.insertAfter("message", message);
pipelineOutput.destroy();
728x90
반응형

댓글