首页 > 编程 > JSP > 正文

!jsp如何调用linux shell

2019-11-02 14:17:29
字体:
来源:转载
供稿:网友

     经常碰到运营部门人要清缓存,而缓存一直存在问题,老在电脑面前处理也不是个办法,想了个方法,通过访问一个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);

东流影院[www.aikan.tv/special/dongliuyingyuan/]

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/ 下就可以访问了

 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表