展会信息港展会大全

jsp如何调用linux shell
来源:互联网   发布日期:2016-03-01 10:45:26   浏览:1704次  

导读: 经常碰到运营部门人要清缓存,而缓存一直存在问题,老在电脑面前处理也不是个办法,想了个方法,通过访问一个jsp页面自动清缓存<%@ page language=...

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

赞助本站

人工智能实验室

相关热词: 开发 编程 android

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港