/** * Returns a command to run the given script. The script interpreter is * inferred by platform: cmd on Windows or bash otherwise. * * @param script File script to run * @return String[] command to run the script */ public static String[] getRunScriptCommand(File script) { String absolutePath = script.getAbsolutePath(); return WINDOWS ? new String[] {"cmd", "/c", absolutePath } : new String[] {"bash", bashQuote(absolutePath) }; }
/** * A command to get a given user's group id list. * The command will get the user's primary group * first and finally get the groups list which includes the primary group. * i.e. the user's primary group will be included twice. * This command does not support Windows and will only return group names. */ public static String[] getGroupsIDForUserCommand(final String user) { //'groups username' command return is inconsistent across different unixes if (WINDOWS) { return new String[]{getWinUtilsPath(), "groups", "-F", "\"" + user + "\""}; } else { String quotedUser = bashQuote(user); return new String[] {"bash", "-c", "id -g " + quotedUser + "; id -G " + quotedUser}; } }
/** * A command to get a given user's groups list. * If the OS is not WINDOWS, the command will get the user's primary group * first and finally get the groups list which includes the primary group. * i.e. the user's primary group will be included twice. */ public static String[] getGroupsForUserCommand(final String user) { //'groups username' command return is inconsistent across different unixes if (WINDOWS) { return new String[] {getWinUtilsPath(), "groups", "-F", "\"" + user + "\""}; } else { String quotedUser = bashQuote(user); return new String[] {"bash", "-c", "id -gn " + quotedUser + "; id -Gn " + quotedUser}; } }
/** Return a command to send a signal to a given pid. */ public static String[] getSignalKillCommand(int code, String pid) { // Code == 0 means check alive if (Shell.WINDOWS) { if (0 == code) { return new String[] {Shell.getWinUtilsPath(), "task", "isAlive", pid }; } else { return new String[] {Shell.getWinUtilsPath(), "task", "kill", pid }; } } // Use the bash-builtin instead of the Unix kill command (usually // /bin/kill) as the bash-builtin supports "--" in all Hadoop supported // OSes. final String quotedPid = bashQuote(pid); if (isSetsidAvailable) { return new String[] { "bash", "-c", "kill -" + code + " -- -" + quotedPid }; } else { return new String[] { "bash", "-c", "kill -" + code + " " + quotedPid }; } }
/** * Returns a command to run the given script. The script interpreter is * inferred by platform: cmd on Windows or bash otherwise. * * @param script File script to run * @return String[] command to run the script */ public static String[] getRunScriptCommand(File script) { String absolutePath = script.getAbsolutePath(); return WINDOWS ? new String[] {"cmd", "/c", absolutePath } : new String[] {"/bin/bash", bashQuote(absolutePath) }; }
/** * Returns a command to run the given script. The script interpreter is * inferred by platform: cmd on Windows or bash otherwise. * * @param script File script to run * @return String[] command to run the script */ public static String[] getRunScriptCommand(File script) { String absolutePath = script.getAbsolutePath(); return WINDOWS ? new String[] {"cmd", "/c", absolutePath } : new String[] {"/bin/bash", bashQuote(absolutePath) }; }
/** * Returns a command to run the given script. The script interpreter is * inferred by platform: cmd on Windows or bash otherwise. * * @param script File script to run * @return String[] command to run the script */ public static String[] getRunScriptCommand(File script) { String absolutePath = script.getAbsolutePath(); return WINDOWS ? new String[] {"cmd", "/c", absolutePath } : new String[] {"/bin/bash", bashQuote(absolutePath) }; }
/** * Returns a command to run the given script. The script interpreter is * inferred by platform: cmd on Windows or bash otherwise. * * @param script File script to run * @return String[] command to run the script */ public static String[] getRunScriptCommand(File script) { String absolutePath = script.getAbsolutePath(); return WINDOWS ? new String[] {"cmd", "/c", absolutePath } : new String[] {"bash", bashQuote(absolutePath) }; }
/** * A command to get a given user's group id list. * The command will get the user's primary group * first and finally get the groups list which includes the primary group. * i.e. the user's primary group will be included twice. * This command does not support Windows and will only return group names. */ public static String[] getGroupsIDForUserCommand(final String user) { //'groups username' command return is inconsistent across different unixes if (WINDOWS) { return new String[]{getWinUtilsPath(), "groups", "-F", "\"" + user + "\""}; } else { String quotedUser = bashQuote(user); return new String[] {"bash", "-c", "id -g " + quotedUser + "; id -G " + quotedUser}; } }
/** * A command to get a given user's groups list. * If the OS is not WINDOWS, the command will get the user's primary group * first and finally get the groups list which includes the primary group. * i.e. the user's primary group will be included twice. */ public static String[] getGroupsForUserCommand(final String user) { //'groups username' command return is inconsistent across different unixes if (WINDOWS) { return new String[] {getWinUtilsPath(), "groups", "-F", "\"" + user + "\""}; } else { String quotedUser = bashQuote(user); return new String[] {"bash", "-c", "id -gn " + quotedUser + "; id -Gn " + quotedUser}; } }
/** * a Unix command to get a given user's groups list. * If the OS is not WINDOWS, the command will get the user's primary group * first and finally get the groups list which includes the primary group. * i.e. the user's primary group will be included twice. */ public static String[] getGroupsForUserCommand(final String user) { //'groups username' command return is inconsistent across different unixes if (WINDOWS) { return new String[] {getWinUtilsPath(), "groups", "-F", "\"" + user + "\""}; } else { String quotedUser = bashQuote(user); return new String[] {"bash", "-c", "id -gn " + quotedUser + "; id -Gn " + quotedUser}; } }
/** * a Unix command to get a given user's groups list. * If the OS is not WINDOWS, the command will get the user's primary group * first and finally get the groups list which includes the primary group. * i.e. the user's primary group will be included twice. */ public static String[] getGroupsForUserCommand(final String user) { //'groups username' command return is inconsistent across different unixes if (WINDOWS) { return new String[] {getWinUtilsPath(), "groups", "-F", "\"" + user + "\""}; } else { String quotedUser = bashQuote(user); return new String[] {"bash", "-c", "id -gn " + quotedUser + "; id -Gn " + quotedUser}; } }
/** * a Unix command to get a given user's groups list. * If the OS is not WINDOWS, the command will get the user's primary group * first and finally get the groups list which includes the primary group. * i.e. the user's primary group will be included twice. */ public static String[] getGroupsForUserCommand(final String user) { //'groups username' command return is inconsistent across different unixes if (WINDOWS) { return new String[] {getWinUtilsPath(), "groups", "-F", "\"" + user + "\""}; } else { String quotedUser = bashQuote(user); return new String[] {"bash", "-c", "id -gn " + quotedUser + "; id -Gn " + quotedUser}; } }
/** Return a command to send a signal to a given pid. */ public static String[] getSignalKillCommand(int code, String pid) { // Code == 0 means check alive if (Shell.WINDOWS) { if (0 == code) { return new String[] {Shell.getWinUtilsPath(), "task", "isAlive", pid }; } else { return new String[] {Shell.getWinUtilsPath(), "task", "kill", pid }; } } // Use the bash-builtin instead of the Unix kill command (usually // /bin/kill) as the bash-builtin supports "--" in all Hadoop supported // OSes. final String quotedPid = bashQuote(pid); if (isSetsidAvailable) { return new String[] { "bash", "-c", "kill -" + code + " -- -" + quotedPid }; } else { return new String[] { "bash", "-c", "kill -" + code + " " + quotedPid }; } }