0

我想创建一个脚本来循环遍历 /etc/passwd 并打印所有用户名和帐户状态。

while read line; do
print username to field1 in user.txt
print status active/disabled in field2 in user.txt
done</etc/passwd
4

1 回答 1

0
while IFS=: read user status placeholder; do
    [[ $status == x ]] && active=active || active=inactive
    echo "$user $active" >> user.txt
done < /etc/passwd
cat user.txt

但是如果第二列是x用户有一个加密的密码,那不代表活跃或不活跃......

man 5 passwd

你应该看看

account expiration date

man 5 shadow
于 2013-02-25T03:58:20.793 回答