| 1 | # | ||
| 2 | # $Id$ | ||
| 3 | # | ||
| 4 | # system::freebsd:who Brik | ||
| 5 | # | ||
| 6 | package Metabrik::System::Freebsd::Who; | ||
| 7 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | 1 | ▶ | use base qw(Metabrik::Shell::Command); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | |||
| 12 | sub brik_properties { | ||
| 13 | return { | ||
| 14 | revision => '$Revision$', | ||
| 15 | tags => [ qw(unstable) ], | ||
| 16 | author => 'GomoR <GomoR[at]metabrik.org>', | ||
| 17 | license => 'http://opensource.org/licenses/BSD-3-Clause', | ||
| 18 | commands => { | ||
| 19 | get => [ ], | ||
| 20 | }, | ||
| 21 | require_binaries => { | ||
| 22 | who => [ ], | ||
| 23 | }, | ||
| 24 | }; | ||
| 25 | } | ||
| 26 | |||
| 27 | sub get { | ||
| 28 | my $self = shift; | ||
| 29 | |||
| 30 | my $cmd = 'who -H'; | ||
| 31 | |||
| 32 | # | ||
| 33 | # FreeBSD 10.2-RELEASE | ||
| 34 | # | ||
| 35 | # 0: NAME LINE TIME FROM | ||
| 36 | # 1: <user> pts/3 Oct 29 10:36 (<ip>) | ||
| 37 | |||
| 38 | my $lines = $self->capture($cmd) or return; | ||
| 39 | |||
| 40 | my $info = { | ||
| 41 | raw => $lines, | ||
| 42 | }; | ||
| 43 | my $first = 1; | ||
| 44 | for my $line (@$lines) { | ||
| 45 | if ($first) { | ||
| 46 | $first = 0; | ||
| 47 | next; | ||
| 48 | } | ||
| 49 | |||
| 50 | $line =~ s{^\s*}{}; | ||
| 51 | $line =~ s{\s*$}{}; | ||
| 52 | |||
| 53 | my @t = $line =~ m{^(\S+)\s+(\S+)\s+(\d+ \S+ \S+)\s+\((\S+)\)$}; | ||
| 54 | |||
| 55 | my $user = $t[0]; | ||
| 56 | my $where = $t[1]; | ||
| 57 | my $time = $t[2]; | ||
| 58 | my $from = $t[3]; | ||
| 59 | |||
| 60 | $where =~ s{/}{_}g; | ||
| 61 | |||
| 62 | $info->{$where} = { | ||
| 63 | user => $user, | ||
| 64 | connection_time => $time, | ||
| 65 | from => $from, | ||
| 66 | }; | ||
| 67 | } | ||
| 68 | |||
| 69 | return $info; | ||
| 70 | } | ||
| 71 | |||
| 72 | 1; | ||
| 73 | |||
| 74 | __END__ | ||