Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm looking for a way to find users who have no logged in the system for 90 days so I can delete or warn them afterwards. Is there a linux command that can do this for me or do I have to write some kind of bash script?
I'm looking for a way to find users who have no logged in the system for 90 days so I can delete or warn them afterwards. Is there a linux command that can do this for me or do I have to write some kind of bash script?
lastlog -b 90
This will get users who never logged in as well, in addition to system users. The former problem can be solved with a grep -vi 'never logged in' though.
I just ran lastlog -b 90, & was a bit disappointed when the list was so filled w/ system/daemon user names that I couldn't easily find the one human that hadn't ever logged in.
I checked the man page & the format of /var/log/lastlog, but I don't see any way, even the possibility of any way, to easily filter on UID or other criteria.
I envision a too complicated script that has to parse the UID's from /etc/passwd in the middle of processing the output from lastlog. I think the approach I am imagining is wrong.
Nice. Not quite as simple as I was hoping for, it's 2 lines ; but way less Byzantine than the calling awk w/in awk than I was envisioning.
BTW, the last time I used grep -f, grep -Ff worked much faster. It was a long list & a recursive grep, & -F made a huge difference. This is not so large a problem; so, while there is a measurable difference, it is not noticeable:
Code:
$ awk -F: '$3 < 1000 {print $1}' /etc/passwd > users_list
$ time lastlog -b 90 | grep -vf users_list
Username Port From Latest
onthego **Never logged in**
avg **Never logged in**
real 0m0.061s
user 0m0.052s
sys 0m0.004s
$ time lastlog -b 90 | grep -vFf users_list
Username Port From Latest
onthego **Never logged in**
avg **Never logged in**
real 0m0.012s
user 0m0.004s
sys 0m0.004s
Thanks for the code, I did find a user I didn't notice except for the filtering.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.