cmdList.toArray(new String[cmdList.size()]), dir); try { s.execute(); allOutput.append(s.getOutput()).append(" "); } catch (Exception e) {
private static void unTarUsingTar(File inFile, File untarDir, boolean gzipped) throws IOException { StringBuffer untarCommand = new StringBuffer(); if (gzipped) { untarCommand.append(" gzip -dc '"); untarCommand.append(FileUtil.makeSecureShellPath(inFile)); untarCommand.append("' | ("); } untarCommand.append("cd '"); untarCommand.append(FileUtil.makeSecureShellPath(untarDir)); untarCommand.append("' && "); untarCommand.append("tar -xf "); if (gzipped) { untarCommand.append(" -)"); } else { untarCommand.append(FileUtil.makeSecureShellPath(inFile)); } String[] shellCmd = { "bash", "-c", untarCommand.toString() }; ShellCommandExecutor shexec = new ShellCommandExecutor(shellCmd); shexec.execute(); int exitcode = shexec.getExitCode(); if (exitcode != 0) { throw new IOException("Error untarring file " + inFile + ". Tar process exited with exit code " + exitcode); } }
String[] args = {"setsid", "bash", "-c", "echo $$"}; shexec = new ShellCommandExecutor(args); shexec.execute(); } catch (IOException ioe) { LOG.debug("setsid is not available on this machine. So not using it.");
String getAllProcessInfoFromShell() { ShellCommandExecutor shellExecutor = new ShellCommandExecutor( new String[] { Shell.WINUTILS, "task", "processList", taskProcessId }); try { shellExecutor.execute(); return shellExecutor.getOutput(); } catch (IOException e) { LOG.error(StringUtils.stringifyException(e)); } return null; }
private static void sendSignal(String pid, int signal) throws IOException { ShellCommandExecutor shexec = null; String[] arg = { "kill", "-" + signal, "--", pid }; shexec = new ShellCommandExecutor(arg); shexec.execute(); }
String getSystemInfoInfoFromShell() { try { ShellCommandExecutor shellExecutor = new ShellCommandExecutor( new String[] {Shell.getWinUtilsFile().getCanonicalPath(), "systeminfo" }); shellExecutor.execute(); return shellExecutor.getOutput(); } catch (IOException e) { LOG.error(StringUtils.stringifyException(e)); } return null; }
private static void sendSignal(String pid, int signal) throws IOException { ShellCommandExecutor shexec = null; String[] arg = { "kill", "-" + signal, "--", pid }; shexec = new ShellCommandExecutor(arg); shexec.execute(); }
String getAllProcessInfoFromShell() { try { ShellCommandExecutor shellExecutor = new ShellCommandExecutor( new String[] {Shell.getWinUtilsFile().getCanonicalPath(), "task", "processList", taskProcessId }); shellExecutor.execute(); return shellExecutor.getOutput(); } catch (IOException e) { LOG.error(StringUtils.stringifyException(e)); } return null; }
shExec = new ShellCommandExecutor(cmd); shExec.execute(); } catch (Shell.ExitCodeException ec) { int returnVal = ec.getExitCode();
partialResolver.execute(); return parsePartialGroupNames( groupNames, partialResolver.getOutput());
executor.execute(); groups = resolveFullGroupNames(executor.getOutput()); } catch (ExitCodeException e) {
shexec.execute(); in = new BufferedReader(new StringReader(shexec.getOutput())); inpMsg = in.readLine();
@Override public void run() { HealthCheckerExitStatus status = HealthCheckerExitStatus.SUCCESS; try { shexec.execute(); } catch (ExitCodeException e) { // ignore the exit code of the script status = HealthCheckerExitStatus.FAILED_WITH_EXIT_CODE; // On Windows, we will not hit the Stream closed IOException // thrown by stdout buffered reader for timeout event. if (Shell.WINDOWS && shexec.isTimedOut()) { status = HealthCheckerExitStatus.TIMED_OUT; } } catch (Exception e) { LOG.warn("Caught exception : " + e.getMessage()); if (!shexec.isTimedOut()) { status = HealthCheckerExitStatus.FAILED_WITH_EXCEPTION; } else { status = HealthCheckerExitStatus.TIMED_OUT; } exceptionStackTrace = StringUtils.stringifyException(e); } finally { if (status == HealthCheckerExitStatus.SUCCESS) { if (hasErrors(shexec.getOutput())) { status = HealthCheckerExitStatus.FAILED; } } reportHealthStatus(status); } }
/** * Change the permissions on a file / directory, recursively, if * needed. * @param filename name of the file whose permissions are to change * @param perm permission string * @param recursive true, if permissions should be changed recursively * @return the exit code from the command. * @throws IOException */ public static int chmod(String filename, String perm, boolean recursive) throws IOException { String [] cmd = Shell.getSetPermissionCommand(perm, recursive); String[] args = new String[cmd.length + 1]; System.arraycopy(cmd, 0, args, 0, cmd.length); args[cmd.length] = new File(filename).getPath(); ShellCommandExecutor shExec = new ShellCommandExecutor(args); try { shExec.execute(); }catch(IOException e) { if(LOG.isDebugEnabled()) { LOG.debug("Error while changing permission : " + filename +" Exception: " + StringUtils.stringifyException(e)); } } return shExec.getExitCode(); }
public static boolean checkIsBashSupported() throws InterruptedIOException { if (Shell.WINDOWS) { return false; } ShellCommandExecutor shexec; boolean supported = true; try { String[] args = {"bash", "-c", "echo 1000"}; shexec = new ShellCommandExecutor(args); shexec.execute(); } catch (InterruptedIOException iioe) { LOG.warn("Interrupted, unable to determine if bash is supported", iioe); throw iioe; } catch (IOException ioe) { LOG.warn("Bash is not supported by the OS", ioe); supported = false; } catch (SecurityException se) { LOG.info("Bash execution is not allowed by the JVM " + "security manager.Considering it not supported."); supported = false; } return supported; }
public HealthReport checkHealth() { HealthCheckerExitStatus status = HealthCheckerExitStatus.SUCCESS; try { // Calling this execute leaves around running executor threads. shexec.execute(); } catch (ExitCodeException e) { // ignore the exit code of the script LOG.warn("Caught exception : " + e + ",exit code:" + e.getExitCode()); status = HealthCheckerExitStatus.FAILED_WITH_EXIT_CODE; } catch (IOException e) { LOG.warn("Caught exception : " + e); status = HealthCheckerExitStatus.FAILED_WITH_EXCEPTION; exceptionStackTrace = org.apache.hadoop.util.StringUtils.stringifyException(e); } finally { if (shexec.isTimedOut()) { status = HealthCheckerExitStatus.TIMED_OUT; } if (status == HealthCheckerExitStatus.SUCCESS) { if (hasErrors(shexec.getOutput())) { status = HealthCheckerExitStatus.FAILED; } } } return new HealthReport(status, getHealthReport(status)); }
/** * Static method to execute a shell command. * Covers most of the simple cases without requiring the user to implement * the <code>Shell</code> interface. * @param env the map of environment key=value * @param cmd shell command to execute. * @param timeout time in milliseconds after which script should be marked timeout * @return the output of the executed command. * @throws IOException on any problem. */ public static String execCommand(Map<String, String> env, String[] cmd, long timeout) throws IOException { ShellCommandExecutor exec = new ShellCommandExecutor(cmd, null, env, timeout); exec.execute(); return exec.getOutput(); }
private static long getConf(String attr) { if(Shell.LINUX) { try { ShellCommandExecutor shellExecutorClk = new ShellCommandExecutor( new String[] {"getconf", attr }); shellExecutorClk.execute(); return Long.parseLong(shellExecutorClk.getOutput().replace("\n", "")); } catch (IOException|NumberFormatException e) { return -1; } } return -1; }
String getSystemInfoInfoFromShell() { try { ShellCommandExecutor shellExecutor = new ShellCommandExecutor( new String[] {Shell.getWinUtilsFile().getCanonicalPath(), "systeminfo" }); shellExecutor.execute(); return shellExecutor.getOutput(); } catch (IOException e) { LOG.error(StringUtils.stringifyException(e)); } return null; }
@Override public void execute() throws IOException { super.execute(); } }