Results 1 to 4 of 4
I want to count the number of users who have logged in multiple terminals ?
How will I get this ?
I always get the total number of users. How ...
- 02-21-2011 #1Just Joined!
- Join Date
- Jan 2009
- Posts
- 63
number of users logged in using multiple terminals
I want to count the number of users who have logged in multiple terminals ?
How will I get this ?
I always get the total number of users. How will I get the uniq number of users with multiple logins ?
- 02-21-2011 #2Linux Newbie
- Join Date
- Apr 2010
- Location
- Novosibirsk, Russia
- Posts
- 136
Code:`users` - print the user names of users currently logged in to the current host
- 02-21-2011 #3Just Joined!
- Join Date
- Jan 2009
- Posts
- 63
- 02-21-2011 #4Linux Newbie
- Join Date
- Apr 2010
- Location
- Novosibirsk, Russia
- Posts
- 136
It's also quite simple I suppose. That's a useful command, which could be used in a script:
would show you all terminals on which $WANTED_USER is currently logged in.Code:$ who | grep $WANTED_USERNAME | awk '{print $2; }'
So, a way to solve your task is to walk over all usernames, registered in system and check what users occupy multiple terminals. Here a small script, written from scratch:
Code:#!/usr/bin/perl use strict; open my $passwd_fd, '<', '/etc/passwd'; my @usernames = grep { s/:.*\s*$//; } <$passwd_fd>; my $cmd; my $ttys; my $cnt; foreach my $user(@usernames) { $cnt = 0; $cmd = "who | grep '$user' | awk '{ print \$2; }'"; $ttys = qx/$cmd/; if($ttys) { $cnt = qx/echo -n '$ttys' | wc -l/; } if($cnt > 1) { print "User '$user' is logged on multiple terminals:\n".$ttys; } }


Reply With Quote
