• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

如何从用户名编程得到其所属的组列表?

发布: 2007-6-08 22:43 | 作者: seanhe | 来源: | 查看: 23次 | 进入软件测试论坛讨论

领测软件测试网
还有如何得知一个组中有哪些用户?
其实就是group和id的功能,但是我找不到相应的函数

 jianyan 回复于:2004-02-03 01:04:43
读一下/etc/passwd这个文件不就行了,hehe

 laoxia 回复于:2004-02-03 01:31:49
/etc/group

 jianyan 回复于:2004-02-03 01:56:59
楼上的兄弟,
/etc/group里面的东东好像不是很准确啊!!!
并不能给出想要的所有人的ID
:)

 laoxia 回复于:2004-02-03 03:01:39
[quote:eb245b63f6="jianyan"]楼上的兄弟,
/etc/group里面的东东好像不是很准确啊!!!
并不能给出想要的所有人的ID
:)[/quote:eb245b63f6]

Yes..you are right

try this

logins  -g  group_name

for example. on my machine

=============================
# logins -g staff
jkzhang         1005    staff           10
irmiller        1006    staff           10
pxia            1007    staff           10
jbohlke         1008    staff           10
=============================

 laoxia 回复于:2004-02-03 03:09:09
[size=18:cf168bc234][b:cf168bc234]Displaying a User's Login Status[/b:cf168bc234][/size:cf168bc234]

Use the logins command to display the status of users who are logged in. Using the logins command with no arguments displays a list of all user and system login accounts. Use the options listed in Table 18-11 to control the output displayed by the logins command.

Table 18-11 Options to the logins Command  
--------------------------------------------------------------------------------
 
Option  Description  
-a  Add two password expiration fields to the display. The fields show how many days a password can remain unused before it automatically becomes inactive as well as the
date that the password expires.  
-d  List logins with duplicate UIDs.  
-m  Display multiple group membership information.  
-o  Format the output into one line of colon-separated fields.  
-p  Display logins with no passwords.  
-s  Display all system logins.  
-t  Sort output by login name instead of by UID.  
-u  Display all user logins.  
-x  Print an extended set of information about each specified user. The extended information displays the home directory, login shell, and password aging information, each on a separate line. The password information includes password status (PS for password, NO for no password, or LK for locked). If the login is passworded, status is followed by the date the password was last changed, the number of days required between changes, and the number of days allowed before a change is required. The password aging information shows the time interval during which the user will receive a password expiration warning message at logon before the password expires.  
-g group  Lists all users belonging to the group, sorted by login. You can specify multiple groups as a comma-separated list.  
-l login  Lists the requested login. You can specify multiple logins as a comma-separated list. Depending on the name service lookup types set in /etc/nsswitch.conf, the information can come from the /etc/passwd and /etc/shadow files and other name services.  

--------------------------------------------------------------------------------
 

The logins command uses the following syntax:

/usr/bin/logins [-admopstux] [-g <group1>,<group2>…]
[-l<login1>,<login2>…]

You can group options together. When you group options, any login that matches any criteria is displayed. When you combine the –l and –g options, a user is listed only once, even if the user belongs to more than one of the specified groups.



--------------------------------------------------------------------------------
NOTE:  You must be superuser to run the logins command.

 jianyan 回复于:2004-02-03 09:01:29
logins 的确是不错不错的东东,楼上还真能查。
但那玩意义好像只能用root才能运行,普通用户不能运行,hehe

 laoxia 回复于:2004-02-03 09:40:49
> 如何从用户名编程得到其所属的组列表? 

groups  user_name

 fudy 回复于:2004-02-03 20:37:24
各位兄弟,你们说的都不是编程阿

 alinker 回复于:2004-02-03 21:47:20
有awk操作下/etc/passwd
取出相同gid那个field的记录,节取uid

成了

 diag 回复于:2004-02-03 23:34:53
楼主说的那个函数。没人知道

 nanaskylead 回复于:2004-02-04 08:52:05
为什么要用函数实现?命令行能做的东西一样可以写在脚本里啊?

 diag 回复于:2004-02-04 09:55:18
admintool 

是怎么来的?

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网