分类:
2011-11-30 23:59:52
原文地址:jsp 调用linux shell 作者:wizardzj
<%@ page language="java" import="java.io.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<%
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/ 下就可以访问了