Geekzone: technology news, blogs, forums
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.

2931 posts

Uber Geek


# 243930 9-Jan-2019 13:47
Send private message

I'll be the first to admit I am not a linux guru, but I do know some basics.


I am working on scraping local user information from servers to see what accounts exist, their state, last login and from which computer they're from. For windows and powershell, this is super simple and I've put it into a pscustomobject/table which can be easily exported - example below.





I am having trouble pulling this information from Linux in a usable way - I can use the 'last' command to pull the last login time, and will need to parse that, so that's not a big problem.
Getting a full list of local user accounts is proving a little difficult though. I have tried:


awk -F: '$3 >= 1000 {print $1}' /etc/passwd


This does print out my user, which is great, but doesn't help with any account status information, and it excludes system accounts which have ID's 0-999. But without the supporting data, just simply "viewing" the accounts isn't very useful. 


Having not worked with linux command line much, also not sure the best way to store the variables to extract it out to CSV. Am I missing some kind of useful toolset that would pull this information?

Create new topic
1000 posts

Ultimate Geek

Lifetime subscriber

  # 2157026 9-Jan-2019 13:56
Send private message

What about lastlog ?


That will provide a list of all accounts, including accounts that haven't logged on

110 posts

Master Geek

  # 2157060 9-Jan-2019 14:30
Send private message

You can combine output of passwd and lastlog, e.g. something like this:


awk -F: '$3 >= 1000 {print $1}' /etc/passwd | while read name; do echo "`lastlog | grep $name` `passwd -S $name`"; done


nobody **Never logged in** nobody L 01/01/2018 0 99999 7 -1
testuser tty3 Sun Dec 9 22:44:06 +1300 2018 testuser P 01/01/2018 7 365 7 -1



passwd -S outputs 7 values:



The first field is the user's login name. The second field indicates if the user account has a locked password (L), has no password (NP), or has a usable password (P). The third field gives the date of the last password change. The next four fields are the minimum age, maximum age, warning period, and inactivity period for the password. These ages are expressed in days.


Create new topic

Twitter and LinkedIn »

Follow us to receive Twitter updates when new discussions are posted in our forums:

Follow us to receive Twitter updates when news items and blogs are posted in our frontpage:

Follow us to receive Twitter updates when tech item prices are listed in our price comparison site:

News »

Logitech introduces new Made for Google keyboard and mouse devices
Posted 16-Oct-2019 13:36

MATTR launches to accelerate decentralised identity
Posted 16-Oct-2019 10:28

Vodafone X-Squad powers up for customers
Posted 16-Oct-2019 08:15

D Link ANZ launches EXO Smart Mesh Wi Fi Routers with McAfee protection
Posted 15-Oct-2019 11:31

Major Japanese retailer partners with smart New Zealand technology IMAGR
Posted 14-Oct-2019 10:29

Ola pioneers one-time passcode feature to fight rideshare fraud
Posted 14-Oct-2019 10:24

Spark Sport new home of NZC matches from 2020
Posted 10-Oct-2019 09:59

Meet Nola, Noel Leeming's new digital employee
Posted 4-Oct-2019 08:07

Registrations for Sprout Accelerator open for 2020 season
Posted 4-Oct-2019 08:02

Teletrac Navman welcomes AI tech leader Jens Meggers as new President
Posted 4-Oct-2019 07:41

Vodafone makes voice of 4G (VoLTE) official
Posted 4-Oct-2019 07:36

2degrees Reaches Milestone of 100,000 Broadband Customers
Posted 1-Oct-2019 09:17

Nokia 1 Plus available in New Zealand from 2nd October
Posted 30-Sep-2019 17:46

Ola integrates Apple Pay as payment method in New Zealand
Posted 25-Sep-2019 09:51

Facebook Portal to land in New Zealand
Posted 19-Sep-2019 18:35

Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.

Support Geekzone »

Our community of supporters help make Geekzone possible. Click the button below to join them.

Support Geezone on PressPatron

Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.

Alternatively, you can receive a daily email with Geekzone updates.