Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How many times ALL users are logged into AIX and db

Status
Not open for further replies.

baggetta

Technical User
Feb 27, 2003
116
US
Is there a way to see how many times a user is logged into our AIX system? I can do it for each single user using this command: who |grep username | wc -l

Doing this one by one is time consuming. I would like a list showing "username ##"

Can I use another command to find out how many times a user is logged into our database. Their process ID will always have this link: /apps/dlc91d/bin/_progres /dbdir/dbname

 
last | more will show you who has logged into the system since the wtmp file was created.

For the database, you might be able to write a query to log when people have signed onto the database. Or you could ps -ef | grep /apps/dlc91d/bin/_progres, but you would almost have to do that continuously and for some databases (like Oracle), the owner of the process would be user oracle, not the login of the person who is in the database.
 
bi, I don't understand what you meant by "last |more". Have you tried to do a more on the wtmp file? Is machine code. I'm trying to find out which users are logged in to my server more than once, but using the command above with the grep, I have to specify the username, and I don't want to do that.
 
man last

last is a command that turns the wtmp file into human readable form. Anyone logged into the system will show up as "still logged in."

You could do a ps -ef | grep pts to get the processes of folks logged in.
 
Try this perl script.

#!/usr/bin/perl

@users = `who | cut -f1 -d " " `;

foreach $user (@users) {
chomp($user);
$countusers{$user} += 1;
}

while(($user, $count) = each %countusers) {
print "$user : $count \n";
}


Bye.
 
One more thing, can you add a sort to this file by either username or their count.

IE:
user1: 5
user2: 5
user3: 4
user4: 1
 
Hi,

This version displays the result sorted by user id.

#!/usr/bin/perl

@users = `who | cut -f1 -d " " `;

foreach $user (@users) {
chomp($user);
$countusers{$user} += 1;
}

foreach $user (sort keys %countusers) {
print "$user $countusers{$user} \n";
}


Bye.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top