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

3204 posts

Uber Geek
+1 received by user: 169


#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
1553 posts

Uber Geek
+1 received by user: 1036

Trusted
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
+1 received by user: 20


  #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








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.