public abstract class ShellUtils extends Object
| Modifier and Type | Class and Description | 
|---|---|
| static class  | ShellUtils.ExitCodeExceptionThis is an IOException with exit code added. | 
| static class  | ShellUtils.OSType | 
| static class  | ShellUtils.ShellCommandExecutorA simple shell command executor. | 
| Modifier and Type | Field and Description | 
|---|---|
| static boolean | FREEBSD | 
| static boolean | LINUX | 
| static org.slf4j.Logger | LOG | 
| static boolean | MAC | 
| static ShellUtils.OSType | osType | 
| static boolean | OTHER | 
| static boolean | SOLARIS | 
| protected long | timeOutIntervalTime after which the executing script would be timedout | 
| static String | TOKEN_SEPARATOR_REGEXToken separator regex used to parse Shell tool outputs | 
| static boolean | WINDOWS | 
| Constructor and Description | 
|---|
| ShellUtils() | 
| ShellUtils(long interval) | 
| ShellUtils(long interval,
          boolean redirectErrorStream) | 
| Modifier and Type | Method and Description | 
|---|---|
| static String | execCommand(Map<String,String> env,
           String... cmd)Static method to execute a shell command. | 
| static String | execCommand(Map<String,String> env,
           String[] cmd,
           long timeout)Static method to execute a shell command. | 
| static String | execCommand(String... cmd)Static method to execute a shell command. | 
| protected abstract String[] | getExecString()return an array containing the command name & its parameters | 
| int | getExitCode()get the exit code | 
| static String[] | getGroupsForUserCommand(String user)a Unix command to get a given user’s groups list. | 
| static ShellLogHandler | getLogHandler(Map stormConf) | 
| Process | getProcess()get the current sub-process executing the given command | 
| boolean | isTimedOut()To check if the passed script to shell command executor timed out or not. | 
| protected abstract void | parseExecResult(BufferedReader lines)Parse the execution result | 
| protected void | run()check to see if a command needs to be executed and execute if needed | 
| protected void | setEnvironment(Map<String,String> env)set the environment for the command | 
| protected void | setWorkingDirectory(File dir)set the working directory | 
public static final org.slf4j.Logger LOG
public static final ShellUtils.OSType osType
public static final boolean WINDOWS
public static final boolean SOLARIS
public static final boolean MAC
public static final boolean FREEBSD
public static final boolean LINUX
public static final boolean OTHER
public static final String TOKEN_SEPARATOR_REGEX
Token separator regex used to parse Shell tool outputs
protected long timeOutInterval
Time after which the executing script would be timedout
public ShellUtils()
public ShellUtils(long interval)
public ShellUtils(long interval,
                  boolean redirectErrorStream)
interval - the minimum duration to wait before re-executing the  command.public int getExitCode()
get the exit code
protected void setEnvironment(Map<String,String> env)
set the environment for the command
env - Mapping of environment variablesprotected void setWorkingDirectory(File dir)
set the working directory
dir - The directory where the command would be executedpublic static String[] getGroupsForUserCommand(String user)
a Unix command to get a given user’s groups list. Windows is not supported.
protected void run()
            throws IOException
check to see if a command needs to be executed and execute if needed
IOExceptionprotected abstract String[] getExecString()
return an array containing the command name & its parameters
protected abstract void parseExecResult(BufferedReader lines) throws IOException
Parse the execution result
IOExceptionpublic Process getProcess()
get the current sub-process executing the given command
public boolean isTimedOut()
To check if the passed script to shell command executor timed out or not.
public static String execCommand(String... cmd) throws IOException
Static method to execute a shell command. Covers most of the simple cases without requiring the user to implement the Shell interface.
cmd - shell command to execute.IOExceptionpublic static String execCommand(Map<String,String> env, String[] cmd, long timeout) throws IOException
Static method to execute a shell command. Covers most of the simple cases without requiring the user to implement the Shell interface.
env - the map of environment key=valuecmd - shell command to execute.timeout - time in milliseconds after which script should be marked timeoutIOExceptionpublic static String execCommand(Map<String,String> env, String... cmd) throws IOException
Static method to execute a shell command. Covers most of the simple cases without requiring the user to implement the Shell interface.
env - the map of environment key=valuecmd - shell command to execute.IOExceptionpublic static ShellLogHandler getLogHandler(Map stormConf)
Copyright © 2022 The Apache Software Foundation. All Rights Reserved.