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


Aaroona

3196 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
dfnt
1512 posts

Uber 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




qwerty123
147 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





News and reviews »

Air New Zealand Starts AI adoption with OpenAI
Posted 24-Jul-2025 16:00


eero Pro 7 Review
Posted 23-Jul-2025 12:07


BeeStation Plus Review
Posted 21-Jul-2025 14:21


eero Unveils New Wi-Fi 7 Products in New Zealand
Posted 21-Jul-2025 00:01


WiZ Introduces HDMI Sync Box and other Light Devices
Posted 20-Jul-2025 17:32


RedShield Enhances DDoS and Bot Attack Protection
Posted 20-Jul-2025 17:26


Seagate Ships 30TB Drives
Posted 17-Jul-2025 11:24


Oclean AirPump A10 Water Flosser Review
Posted 13-Jul-2025 11:05


Samsung Galaxy Z Fold7: Raising the Bar for Smartphones
Posted 10-Jul-2025 02:01


Samsung Galaxy Z Flip7 Brings New Edge-To-Edge FlexWindow
Posted 10-Jul-2025 02:01


Epson Launches New AM-C550Z WorkForce Enterprise printer
Posted 9-Jul-2025 18:22


Samsung Releases Smart Monitor M9
Posted 9-Jul-2025 17:46


Nearly Half of Older Kiwis Still Write their Passwords on Paper
Posted 9-Jul-2025 08:42


D-Link 4G+ Cat6 Wi-Fi 6 DWR-933M Mobile Hotspot Review
Posted 1-Jul-2025 11:34


Oppo A5 Series Launches With New Levels of Durability
Posted 30-Jun-2025 10:15









Geekzone Live »

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



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.