我正在尝试找到提取 Linux 用户报告以及其中一个是管理员的最佳方法。目标是 Debian (8,9) 和 Ubuntu (18,20)。最终报告会很长,所以我希望第一行中的主机名来标识每个 VM。我还想要一份简短的报告,只有用户名,而不是所有详细信息..
我的代码在将其推送到多个主机时(通过 pssh)带来了一些不相关的信息:
#!/bin/bash
_l="/etc/login.defs"
_p="/etc/passwd"
## get mini UID limit ##
l=$(grep "^UID_MIN" $_l)
## get max UID limit ##
l1=$(grep "^UID_MAX" $_l)
echo ""
echo `hostname`
echo ""
echo "----------[ User Accounts ]---------------"
awk -F':' -v "min=${l##UID_MIN}" -v "max=${l1##UID_MAX}" '{ if ( $3 >= min && $3 <= max && $7 != "/sbin/nologin" ) print $0 }' "$_p"
#users with UID >= 1000 (MIN) and UID <= 60000 (MAX)
#these users are allowed to login into system if shell is bash/csh/tcsh/ksh as defined in the /etc/shells file
echo "----------[ from which, Admin Accounts ]---------------"
echo `grep '^sudo:.*$' /etc/group | cut -d: -f4`
#users in sudoers group
exit 0
它会抛出如下垃圾:
谢谢你的建议。