Chinaunix首页 | 论坛 | 博客
  • 博客访问: 94471
  • 博文数量: 27
  • 博客积分: 97
  • 博客等级: 民兵
  • 技术积分: 458
  • 用 户 组: 普通用户
  • 注册时间: 2011-12-02 00:11
文章分类
文章存档

2012年(10)

2011年(17)

分类:

2011-12-02 00:14:21

原文地址:jsp 调用linux shell 作者:wizardzj

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

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

<%

String path = request.getContextPath();

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

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

+ path + "/";

%>

shell

<%

String cmds = "monitor.sh";

try {

Process process;

process = Runtime.getRuntime().exec("sh /opt/test.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("
");

}

if(input!=null){

input.close();

}

} catch (Exception e) {

e.printStackTrace();

}

%>

 

test.sh 脚本内容

echo 'flush_all' | nc 192.168.10.73 11211

将该脚本放到jboss/server/default/deploy/jboss-web.deployer/ROOT.war/ 下就可以访问了

 

阅读(1253) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~