-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
执行脚本的用户名超过8个字符时无法执行脚本 #62
Conversation
👍 问题收到 @xiongchen2012 我看看你实现的解法 |
问题测试分析找了一台机器测试超过8个字符的用户名: $ ps -eo comm,user,ruser,uid
COMMAND USER RUSER UID
init root root 0
sshd root root 0
crond root root 0
...
java admin admin 662
...
bash 59504 59504 59504
ps 59504 59504 59504
...
$ ps -eo comm,user -o ruser=${USER} -o uid
COMMAND USER username_long UID
init root root 0
sshd root root 0
crond root root 0
java admin admin 662
bash 59504 username_long 59504
ps 59504 username_long 59504 解释说明:
- ps -Leo pid,lwp,user,comm,pcpu --no-headers | {
+ ps -Leo pid,lwp -o ruser=${USER} -o comm,pcpu --no-headers | { 按你上面的修改,如果有个用户比 你当前用户名 还长的话,还是会有截断的bug。 解法确定了是列宽导致截断的问题,看了一下 -o format
User-defined format. format is a single argument in the form of a
blank-separated or comma-separated list, which offers a way to specify
individual output columns. The recognized keywords are described in the
STANDARD FORMAT SPECIFIERS section below. Headers may be renamed (ps -o
pid,ruser=RealUser -o comm=Command) as desired. If all column headers are
empty (ps -o pid= -o comm=) then the header line will not be output.
Column width will increase as needed for wide headers; this may be used to
widen up columns such as WCHAN (ps -o pid,wchan=WIDE-WCHAN-COLUMN -o comm).
Explicit width control (ps opid,wchan:42,cmd) is offered too.
... 即这一句: 验证$ ps -eo comm,user:20,ruser,uid
COMMAND USER RUSER UID
init root root 0
sshd root root 0
crond root root 0
...
java admin admin 662
...
bash username_long 59504 59504
ps username_long 59504 59504
... 实现修改- ps -Leo pid,lwp,user,comm,pcpu --no-headers | {
+ ps -Leo pid,lwp,user:80,comm,pcpu --no-headers | { 假定没有超过80字符的用户名了,这个工程实现上实际上足够了 😸 Done! @xiongchen2012 |
@xiongchen2012 PR已经合并 另外,实现优化 也提交了, 见 f817da7 @xiongchen2012 麻烦测试一下,在你的环境是不是也是OK的?? 💓 ❤️ Thanks for your bug submission and implementation commit! ❤️ |
Merge pull request #62 from xiongchen2012/master
Nice work~ |
@xiongchen2012 方便在你的环境测试一下?结果如何? |
已经OK了,谢谢。 |
修改了实现,没有 修改参见 808a2e3 :
|
Merge pull request #62 from xiongchen2012/master
ps -o user参数,当用户超过8个时,超过部分会显示为+号。例如:whoami=njiclscy-7
执行脚本提示:
这个问题导致脚本无法执行。但实际上启动Java进程的用户确实是
njiclscy-7
PR的修改方法是取出当前用户名,使用
ruser
选项输出用户名。