下面的脚本可以用来查看linux中每个组中的用户,它依次读取/etc/group每一行,对于其中每一行,都去遍历一遍/etc/passwd,如果group id匹配,打打印出组名和用户名。

#!/bin/sh
# This script will print all groups and all users in each group.
while read gline
do 
	groupname=`echo $gline | awk -F":" '{print $1}'`
	groupidgrp=`echo $gline | awk -F":" '{print $3}'`
	hasUser=0
	
	while read uline
	do
		usename=`echo $uline | awk -F":" '{print $1}'`
		groupidpwd=`echo $uline | awk -F":" '{print $4}'`
		
		if [ "$groupidgrp" = "$groupidpwd" ]; then
			echo "$groupname:$usename"
			hasUser=1
		fi
	done < /etc/passwd
	
	if [ $hasUser -eq 0 ]; then
		echo "Group $groupname has no user in it"
	fi
	
done < /etc/group


GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:2 个月前 )
186a802e added ecosystem file for PM2 4 年前
5def40a3 Add host customization support for the NodeJS version 4 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐