25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

32 lines
752 B

  1. #!/usr/bin/env perl
  2. #
  3. # Because i'm lazy and sick of typing in getent passwd $someusername/uid
  4. #
  5. my %who_cmds = ("solaris", "/bin/who -q",
  6. "linux", "/usr/bin/who -q",
  7. "darwin", "/usr/bin/who -q",
  8. );
  9. my $who_cmd = $who_cmds{$^O};
  10. local %users = ();
  11. foreach my $l (qx/$who_cmd/){
  12. next if($l =~ m/^\#.*/);
  13. foreach my $user (split(/\s+/,$l)){
  14. unless(exists($users{$user})){
  15. $users{$user} = 0;
  16. }else{
  17. $users{$user}++;
  18. };
  19. };
  20. };
  21. foreach my $user (keys %users){
  22. my $gecos = ( getpwnam($user) )[6];
  23. my $count = $users{$user} + 1;
  24. my $output = "$user\, ".((defined($gecos)) ? "$gecos, " : '')."is logged in on $count tty".(($count>1) ? "\'s" : '')."\n";
  25. print $output;
  26. };