Find the answer to your Linux question:
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just 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 ?

  2. #2
    Linux Newbie
    Join Date
    Apr 2010
    Location
    Novosibirsk, Russia
    Posts
    145

    Post

    Code:
    `users` -  print the user names of users currently logged in to the current host

  3. #3
    Just Joined!
    Join Date
    Jan 2009
    Posts
    63
    Quote Originally Posted by Schmidt View Post
    Code:
    `users` -  print the user names of users currently logged in to the current host
    No I want to count the number users whose names are repeated only.

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Newbie
    Join Date
    Apr 2010
    Location
    Novosibirsk, Russia
    Posts
    145

    Post

    It's also quite simple I suppose. That's a useful command, which could be used in a script:

    Code:
    $  who | grep $WANTED_USERNAME | awk '{print $2; }'
    would show you all terminals on which $WANTED_USER is currently logged in.

    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;
    	}
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •