Skip to content

Commit

Permalink
facts: fix server.Users with getent
Browse files Browse the repository at this point in the history
  • Loading branch information
bauen1 committed Oct 17, 2024
1 parent 932696f commit 2375eec
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pyinfra/facts/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,10 @@ class Users(FactBase):
}
"""

def command(self):
def command(self) -> str:
return """
for i in `getent passwd | cut -d: -f1`; do
ENTRY=`grep ^$i: $(getent passwd)`;
ENTRY=`getent passwd | grep ^$i:`;
LASTLOG_RAW=`(lastlog -u $i 2> /dev/null || lastlogin $i 2> /dev/null)`;
LASTLOG=`echo $LASTLOG_RAW | grep ^$i | tr -s ' '`;
PASSWORD=`grep ^$i: /etc/shadow | cut -d: -f2`;
Expand Down
5 changes: 3 additions & 2 deletions tests/facts/server.Users/mixed.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"freebsd:*:1001:1001:FreeBSD:/home/freebsd:/bin/sh|freebsd|freebsd|freebsd pts/0 10.1.10.10 Thu Aug 31 05:37:58 2023|$bsdpw$",
"freebsdnologin:*:1001:1001:FreeBSD NoLogin:/home/freebsdnologin:/bin/sh|freebsdnologin|freebsdnologin||"
],
"command": "for i in `cat /etc/passwd | cut -d: -f1`; do\n ENTRY=`grep ^$i: /etc/passwd`;\n LASTLOG_RAW=`(lastlog -u $i 2> /dev/null || lastlogin $i 2> /dev/null)`;\n LASTLOG=`echo $LASTLOG_RAW | grep ^$i | tr -s ' '`;\n PASSWORD=`grep ^$i: /etc/shadow | cut -d: -f2`;\n echo \"$ENTRY|`id -gn $i`|`id -Gn $i`|$LASTLOG|$PASSWORD\";\n done",
"command": "for i in `getent passwd | cut -d: -f1`; do\n ENTRY=`getent passwd | grep ^$i:`;\n LASTLOG_RAW=`(lastlog -u $i 2> /dev/null || lastlogin $i 2> /dev/null)`;\n LASTLOG=`echo $LASTLOG_RAW | grep ^$i | tr -s ' '`;\n PASSWORD=`grep ^$i: /etc/shadow | cut -d: -f2`;\n echo \"$ENTRY|`id -gn $i`|`id -Gn $i`|$LASTLOG|$PASSWORD\";\n done",
"requires_command": "getent",
"fact": {
"root": {
"home": "/root",
Expand Down Expand Up @@ -104,4 +105,4 @@
"password": ""
}
}
}
}

0 comments on commit 2375eec

Please sign in to comment.