<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> <%@ page trimDirectiveWhitespaces="true" %> <%@ page import="java.io.*" %> <%! private String getParameterOrDefault(HttpServletRequest request, String param, String defaultValue) { return (request.getParameter(param) == null || request.getParameter(param).equals("") ? defaultValue : request.getParameter(param)); } private boolean isNullOrEmpty(String param) { return param == null || param.equals(""); } %> <% // This param helps us to know what step we are String action = getParameterOrDefault(request, "action", null); String team = getParameterOrDefault(request, "team", ""); String message = getParameterOrDefault(request, "message", ""); if(action == null) { // Code to receive alarm data and return input form (first call when action is null) %>



Max length: 150

<% } else if(action.equals("submit")) { // Code to receive user input, execute the script and return the result (second call when action param equals submit) ProcessBuilder processBuilder = null; Process process = null; BufferedReader reader = null; StringBuilder script_output = null; try { processBuilder = new ProcessBuilder(); // Replace your command here processBuilder.command("/bin/bash", "-c", "echo Invoked: " + team + " " + message); process = processBuilder.start(); reader = new BufferedReader(new InputStreamReader(process.getInputStream())); script_output = new StringBuilder(); String line = null; while((line = reader.readLine()) != null) { script_output.append(line + "
"); } String retVal = (process.waitFor() == 0 ? "SUCCESS" : "FAIL"); %> Command execution: <%=retVal%>

Command output:

<%=script_output%>
<% } catch(Exception e) { out.write("Error occured while executing server side action"); // This line will print the exception in tomcat catalina.out log e.printStackTrace(); } finally { script_output = null; if(reader != null) reader.close(); reader = null; process = null; } } else { // Unknown action out.write("Error occured: action " + action + " not recognized"); } %>