AIX超过8个字符的用户名的处理
近期发现有些系统设计用户名时超过8个字符,希望设计时尽量避免,但如果木已成舟,那可能会对很多软件产生错误影响,比如一些使用脚本的软件。
举例:
[ssjs12a05][xinmin12345][/home]#ls -latr
total 40
drwxr-xr-x 2 guest usr 256 Oct 08 2008 guest
-rw-r--r-- 1 root system 0 Dec 22 02:32 -a
drwxr-xr-x 3 root system 256 Dec 22 03:02 mxin
drwx------ 2 root system 256 Dec 22 12:47 lost+found
drwxr-xr-x 2 root system 256 Jan 19 13:06 scripts
drwxr-xr-x 2 root system 4096 Mar 03 11:50 TT_DB
drwxr-x--- 5 cognos staff 4096 Mar 03 12:26 cognos
drwxr-x--- 2 901 901 256 Mar 03 20:48 bbb
drwxr-x--- 2 902 901 256 Mar 03 21:30 cc
drwxr-x--- 2 weblogic bea 256 Mar 08 10:25 weblogic
drwxr-x--- 3 oradev dba 4096 Mar 09 09:46 oradev
drwxr-xr-x 32 root system 4096 Mar 09 14:19 ..
drwxr-xr-x 13 bin bin 4096 Mar 09 14:51 .
drwxr-x--- 2 xinmin12 staff 256 Mar 09 14:52 xinmin12345
如果使用ls -l试图得到xinmin12345这个目录的属主时,实际会返回xinmin12,后面的345被截掉,而xinmin12这个用户根本不存在。同样问题在ps -ef时也存在。
解决:
了解有问题的软件调用了那些shell命令,至少如下办法可以处理ps,ls.
在.profile里加入
alias ls='ls -X'
alias ps='ps -X'
验证:
[ssjs12a05][xinmin12345][/home/xinmin12345]#ls -latr
total 24
drwxr-xr-x 13 bin bin 4096 Mar 09 14:51 ..
drwxr-x--- 2 xinmin12345 staff 256 Mar 09 14:52 .
-rwxr----- 1 xinmin12345 staff 287 Mar 09 15:06 .profile
-rw------- 1 xinmin12345 staff 326 Mar 09 15:06 .sh_history_(10.25.73.94)
原理:
ls,ps都有一个-X参数
-X
Prints long user names when used with other flags that display user names. The upper limit is determined by the
max_logname ODM attribute in the PdAt and CuAt object classes. If a user name is greater than the max_logname
attribute, it will be truncated to the number of characters as specified by the max_logname attribute, less one
character.
而alias的作用是自动加上-X参数.
.profile的作用是该用户进入是执行这个动作