/** a Unix command to get the current user's name */ public final static String USER_NAME_COMMAND = "whoami"; /** a Unix command to get the current user's groups list */ public static String[] getGroupsCommand() { return new String[]{"bash", "-c", "groups"}; } /** a Unix command to get a given user's groups list */ public static String[] getGroupsForUserCommand(final String user) { //'groups username' command return is non-consistent across different unixes return new String [] {"bash", "-c", "id -Gn " + user}; } /** a Unix command to get a given netgroup's user list */ public static String[] getUsersForNetgroupCommand(final String netgroup) { //'groups username' command return is non-consistent across different unixes return new String [] {"bash", "-c", "getent netgroup " + netgroup}; } /** a Unix command to set permission */ public static final String SET_PERMISSION_COMMAND = "chmod"; /** a Unix command to set owner */ public static final String SET_OWNER_COMMAND = "chown"; public static final String SET_GROUP_COMMAND = "chgrp"; /** Return a Unix command to get permission information. */ public static String[] getGET_PERMISSION_COMMAND() { //force /bin/ls, except on windows. return new String[] {(WINDOWS ? "ls" : "/bin/ls"), "-ld"}; }
So, a simple way to solve this.
-
create a shell script file named as iamwho.sh and its content as simple as below,
echo "hadoopuser"
-
edit .bash_profile
vi ~/.bash_profile
-
add a line as below,
alias whoami="~/local/bin/iamwho.sh"
-
enable the modifition in current shell console,
source ~/.bash_profile
-
run command to check whoami command has been overwrited.
[yiyujia@localhost bin]$ whoami hadoopuser [yiyujia@localhost bin]$
No comments:
Post a Comment