Skip to content

Commit

Permalink
fix: lastlog is always null
Browse files Browse the repository at this point in the history
lastlog output in facts server.Users was always null when using lastlog command
  • Loading branch information
ingstem committed Jan 13, 2025
1 parent 935ce07 commit 74b7d56
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 1 addition & 2 deletions pyinfra/facts/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,7 @@ def command(self):
for i in `cat /etc/passwd | cut -d: -f1`; do
ENTRY=`grep ^$i: /etc/passwd`;
LASTLOG_RAW=`(lastlog -u $i 2> /dev/null || lastlogin $i 2> /dev/null)`;
LASTLOG=`echo $LASTLOG_RAW | grep ^$i | tr -s ' '`;
LASTLOG=`(((lastlog -u $i || lastlogin $i) 2> /dev/null) | grep ^$i | tr -s ' ')`;
PASSWORD=`grep ^$i: /etc/shadow | cut -d: -f2`;
echo "$ENTRY|`id -gn $i`|`id -Gn $i`|$LASTLOG|$PASSWORD";
done
Expand Down
4 changes: 2 additions & 2 deletions tests/facts/server.Users/mixed.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"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 `cat /etc/passwd | cut -d: -f1`; do\n ENTRY=`grep ^$i: /etc/passwd`;\n LASTLOG=`(((lastlog -u $i || lastlogin $i) 2> /dev/null) | 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",
"fact": {
"root": {
"home": "/root",
Expand Down Expand Up @@ -104,4 +104,4 @@
"password": ""
}
}
}
}

0 comments on commit 74b7d56

Please sign in to comment.