11package root .core .repository .implement ;
22
3- import java .io .IOException ;
43import java .io .InputStream ;
54import java .time .LocalDate ;
65import java .util .ArrayList ;
1110import org .apache .commons .io .IOUtils ;
1211
1312import com .jcraft .jsch .Channel ;
14- import com .jcraft .jsch .JSchException ;
1513import com .jcraft .jsch .Session ;
1614
1715import lombok .extern .slf4j .Slf4j ;
@@ -42,9 +40,9 @@ public String getServerName() {
4240 public int getAlertLogFileLineCount (AlertLogCommand alc ) {
4341 int fileLineCnt = 0 ;
4442 try {
45- String command = "cat " + alc . getReadFilePath () + " | wc -l" ;
46- String executeResult = executeCommand (command );
47- fileLineCnt = Integer .parseInt (executeResult . trim () );
43+ String command = String . format ( "cat %s | wc -l", alc . getReadFilePath ()) ;
44+ String executeResult = jsch . executeCommand (command );
45+ fileLineCnt = Integer .parseInt (executeResult );
4846 } catch (Exception e ) {
4947 log .error (e .getMessage ());
5048 }
@@ -56,8 +54,8 @@ public int getAlertLogFileLineCount(AlertLogCommand alc) {
5654 public String checkAlertLog (AlertLogCommand alc ) {
5755 String result = "" ;
5856 try {
59- String command = "tail -" + alc .getReadLine () + " " + alc .getReadFilePath ();
60- result = executeCommand (command );
57+ String command = String . format ( "tail -%d %s" , alc .getReadLine (), alc .getReadFilePath () );
58+ result = jsch . executeCommand (command );
6159 } catch (Exception e ) {
6260 log .error (e .getMessage ());
6361 }
@@ -252,18 +250,4 @@ private String getAlertLogStringFromCertainDate(AlertLogCommand alc, String star
252250
253251 return fullAlertLogString ;
254252 }
255-
256- private String executeCommand (String command ) throws JSchException , IOException {
257- String result = null ;
258-
259- Session session = jsch .getSession ();
260- session .connect ();
261- Channel channel = jsch .openExecChannel (session , command );
262- InputStream in = jsch .connectChannel (channel );
263- result = IOUtils .toString (in , "UTF-8" );
264- jsch .disConnectChannel (channel );
265- jsch .disConnect (session );
266-
267- return result ;
268- }
269253}
0 commit comments