Sponsored Content
Top Forums Shell Programming and Scripting (RHEL, Bash) List users and check if they have logged on during the last 2 months Post 302859775 by gacanepa on Thursday 3rd of October 2013 08:02:47 PM
Old 10-03-2013
Lightbulb (RHEL, Bash) List users and check if they have logged on during the last 2 months

Hi everyone,
At work we were told to check the list of users of an application server and delete all those that have left the company or don't need access to the application anymore. Here's what I came up with. Would you be as kind as to tell me your opinion and whether there is a faster / easier way to accomplish the same thing?
1) Save the list of user names (1st field in /etc/passwd) in a text file (~500 users).
2) Merge /var/log/wtmp and /var/log/wtmp.1 (logrotate is configured to keep only 1 rotated wtmp log) into a single file with
Code:
cat /var/log/wtmp.1 /var/log/wtmp > wtmp

3) Convert the wtmp file (which is of type data):
Code:
gacanepa@Gabriel-PC ~ $ file /var/log/wtmp
/var/log/wtmp: data

to a plain text file sorted by 1st field (user names) and filtered by last occurrence of user name:
Code:
last -f wtmp | sort -uk1,1 > wtmp.txt

4) Check one by one the list of users created in step #1 to see whether they appear in the wtmp.txt file. If they don't appear in this file, which lists the logins for the current and past month, it means they haven't logged on during the same period, and we can consider deleting them.
5) Each "inactive user" is logged into
Some points to consider:
1) Here's the section of /var/log/wtmp in our logrotate.conf file:
Code:
# no packages own wtmp, or btmp -- we'll rotate them here
/var/log/wtmp {
    monthly
    create 0664 root utmp
    rotate 1
}

Unfortunately, we can't edit it.
2) For the same reasons as above we can't use chage either to disable accounts.
I hope I made myself clear enough Smilie. Any suggestions will be more than welcome.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Trying to get list of logged on users sorted

I'm trying to execute a single shell command that will give me a sorted list of all the users currently logged into the system, displaying the users name as it appears in /etc/passwd. I've tried awk -F: '{print $1}' /etc/passwd | xargs finger -s | cut -c11-28 | uniq This list whoever does... (7 Replies)
Discussion started by: kungfuice
7 Replies

2. Post Here to Contact Site Administrators and Moderators

logged out users

how to find out users who logged out within 5 minutes (1 Reply)
Discussion started by: roshni
1 Replies

3. UNIX for Dummies Questions & Answers

List all inactive users who has not logged on since last 90 days

Hi, Can I get a script to list out all the users, who has not logged on since last 90 days. Last command in not working due due to /var/adm/wtmpx is more than 2 GB. Thanks in advance. Regards, Roni (10 Replies)
Discussion started by: manasranjanpand
10 Replies

4. Solaris

List all inactive users who has not logged on since last 90 days

I need actuall script which List all inactive users who has not logged on since last 90 days Thanks in advance. Di! (17 Replies)
Discussion started by: haridham
17 Replies

5. Shell Programming and Scripting

Script to check users logged out

Hi, Here is the script that I have written to check if a particular user is has logged out, and if yes, then a mail needs to be sent to the management the details of whatever has been captured by the script command. echo "The current users are:" who | awk '{print $1}' | sort > temp1 cp... (1 Reply)
Discussion started by: ggayathri
1 Replies

6. UNIX for Dummies Questions & Answers

How to do a login time and date list of users never logged on?

Hello, I'm trying to do a list of user that never connected to a couple of servers. I want to do a diff between the servers lists, and print out only the users that never has logged on each server. Here my first step : SERVER01: # finger `egrep -v -e "^\s*#" /etc/passwd | awk '{ print $1 }' |... (4 Replies)
Discussion started by: gogol_bordello
4 Replies

7. Programming

Get the list of logged in users

How can I get the list of logged in users in the system programmatically? I can get the list with 'who' or 'users' commands but I need to get the list programmatically... May someone help, please? Thanks in advance. (2 Replies)
Discussion started by: xyzt
2 Replies

8. UNIX for Dummies Questions & Answers

How many users are logged in?

How do I find this out? I have a feeling its a simple command such as who, but I just don't know what it is. I've had a search on here but either I can't put it into the right search criteria or there isn't a topic on it. Thanks. EDIT: Delete this thread, as I posted it I noticed the... (0 Replies)
Discussion started by: chris_rabz
0 Replies

9. Shell Programming and Scripting

Bash Help: users who are not logged into the system to display

A Newbie here, I am working on a script and am having problems with the else part of the script. I can't get the users who are not logged into the system to display on the screen with their username and the text "The user is not logged in". I am sure it is something simple and stupid, but I... (5 Replies)
Discussion started by: rchirico
5 Replies

10. Shell Programming and Scripting

How to show a list of currently logged in and logging out users?

Hi Guys! I am sure that this question might appeared previously, but I still don't know how to show a list of logged out users. Please help with this! Thanks in advance:) (5 Replies)
Discussion started by: saloliubliu
5 Replies
All times are GMT -4. The time now is 07:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy