萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> jsp編程 >> jsp如何調用linux shell

jsp如何調用linux shell

     經常碰到運營部門人要清緩存,而緩存一直存在問題,老在電腦面前處理也不是個辦法,想了個方法,通過訪問一個jsp頁面自動清緩存 
 

<%@ page language="java" import="java.io.*" pageEncoding="UTF-8"%>

<%

String path = request.getContextPath();

String basePath = request.getScheme() + "://"

+ request.getServerName() + ":" + request.getServerPort()

+ path + "/";

 

 

%>

<html>

<head>

<title>shell</title>

</head>

<body>

<%

String cmds = "monitor.sh";

try {

 

Process process;

process = Runtime.getRuntime().exec("sh /opt/wzx/monitor.sh");

InputStreamReader ir = new InputStreamReader(process

.getInputStream());

LineNumberReader input = new LineNumberReader(ir);

String line;

process.waitFor();

while ((line = input.readLine()) != null){

out.print(line);

out.print("<br/>");

}

if(input!=null){

input.close();

}

 

} catch (Exception e) {

e.printStackTrace();

}

 

%>

 

</body>

</html>

 

test.sh 腳本內容

echo 'flush_all' | nc 192.168.10.73 11211

將該腳本放到jboss/server/default/deploy/jboss-web.deployer/ROOT.war/ 下就可以訪問了

 

copyright © 萬盛學電腦網 all rights reserved