public static String exec(String cmd) {
        try {
            String[] cmdA = { "/bin/sh", "-c", cmd };
            Process process = Runtime.getRuntime().exec(cmdA);
            LineNumberReader br = new LineNumberReader(new InputStreamReader(
                    process.getInputStream()));
            StringBuffer sb = new StringBuffer();
            String line;
            while ((line = br.readLine()) != null) {
                System.out.println(line);
                sb.append(line).append("\n");
            }

            return sb.length() > 0 ? sb.deleteCharAt(sb.length()-1).toString() : sb.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }