Skip to content

Instantly share code, notes, and snippets.

@badvision
Last active May 19, 2016 20:29
Show Gist options
  • Save badvision/9913f6c9974bca5d549c370d4065088b to your computer and use it in GitHub Desktop.
Save badvision/9913f6c9974bca5d549c370d4065088b to your computer and use it in GitHub Desktop.
Call the *nix command line "df -h" to obtain the disk usage of the server
<%@page session="false" contentType="text/html; charset=utf-8"
pageEncoding="UTF-8" import="java.lang.*,java.io.*"%><%
Process p = Runtime.getRuntime().exec("df",new String[]{"-h"});
p.waitFor();
%><h2>STDERR:</h2><pre><%
String line;
BufferedReader error = new BufferedReader(new InputStreamReader(p.getErrorStream()));
while((line = error.readLine()) != null){
%><%=line%>
<%
}
error.close();
%></pre><h2>STDOUT:</h2><pre><%
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
while((line=input.readLine()) != null){
%><%=line%>
<%
}
input.close();
%>
</pre>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment