Skip to content

Commit 2375eec

Browse files
committed
facts: fix server.Users with getent
1 parent 932696f commit 2375eec

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

pyinfra/facts/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,10 +530,10 @@ class Users(FactBase):
530530
}
531531
"""
532532

533-
def command(self):
533+
def command(self) -> str:
534534
return """
535535
for i in `getent passwd | cut -d: -f1`; do
536-
ENTRY=`grep ^$i: $(getent passwd)`;
536+
ENTRY=`getent passwd | grep ^$i:`;
537537
LASTLOG_RAW=`(lastlog -u $i 2> /dev/null || lastlogin $i 2> /dev/null)`;
538538
LASTLOG=`echo $LASTLOG_RAW | grep ^$i | tr -s ' '`;
539539
PASSWORD=`grep ^$i: /etc/shadow | cut -d: -f2`;

tests/facts/server.Users/mixed.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"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$",
99
"freebsdnologin:*:1001:1001:FreeBSD NoLogin:/home/freebsdnologin:/bin/sh|freebsdnologin|freebsdnologin||"
1010
],
11-
"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",
11+
"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",
12+
"requires_command": "getent",
1213
"fact": {
1314
"root": {
1415
"home": "/root",
@@ -104,4 +105,4 @@
104105
"password": ""
105106
}
106107
}
107-
}
108+
}

0 commit comments

Comments
 (0)