打印到文件bash用户名和帐户状态

时间:2013-02-25 03:53:52

标签: bash

我想创建一个循环遍历/ 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

1 个答案:

答案 0 :(得分: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

in

man 5 shadow