shell脚本: 查看linux用户组,以及每个组中有哪些用户
linux-dash
A beautiful web dashboard for Linux
项目地址:https://gitcode.com/gh_mirrors/li/linux-dash
免费下载资源
·
下面的脚本可以用来查看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 年前
更多推荐
已为社区贡献12条内容
所有评论(0)