home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl
- #
- # program to merge who and w output to add a whence column.
- # for example
- #
- # % perl nw
- # 8:43am up 13 days, 11:18, 55 users, load average: 0.93, 0.74, 0.62
- # User tty whence login@ idle JCPU PCPU what
- # bianchi ttyp0 sherlock 12:50pm 38:56 25:28 21 -ksh
- # daboub ttyp1 triton 12:56pm 17:57 48 6 -tcsh[daboub]
- # aage ttyp2 daffy 5:18pm 15:25 7:39 7:39 -tcsh[aage]
- # eharbin ttyp3 priam 6:34pm 18 47 36 -tcsh[eharbin]
- # feaux ttyp4 adagio 8:51pm 9:41 2:15 3 gnumacs llib-lc.c
- # eharbin ttyp6 priam 8:34am 3 -tcsh[eharbin]
- # bianchi ttyp7 sherlock 5:20pm 46:18 1 1 -ksh
- # watson ttypa balihai 8:49am 19:02 6 3 adb -k vmunix mm.core
- # (etc)
- #
-
- $cols = ($ENV{"TERMCAP"} =~ /:co#(\d+):/) ? $1 : 80;
-
- $PIPE = "/bin/who|";
- open PIPE || die "$0: can't open $PIPE: $!\n";
-
- while (<PIPE>) {
- chop; split;
- $users{$_[1]} = $_[0];
- next unless $#_ > 4;
- ( $whence = $_[5] ) =~ s/^\((.*)\)$/\1/;
- $whence =~ s/(.*):.*/$1/;
- $whence =~ s/(................).*/$1/;
- $whence{$_[1]} = $whence;
- }
-
- $PIPE = "/usr/ucb/w @ARGV|"; open PIPE || die "$0: can't open $PIPE: $!\n";
- $_ = <PIPE>; print;
-
- $_ = <PIPE>;
- s/^(.................).(.*)$/$1whence $2/;
- print;
-
- while (<PIPE>) {
- chop; split;
- $whence = ($users{$_[1]} eq $_[0]) ? $whence{$_[1]} : "(new login)";
- /(.................).(.*)/;
- $line = sprintf ("%s%-10s%s", $1, $whence, $2);
- eval '$line =~ s/^(' . ('.' x $cols) . ').*/$1/';
- print $line,"\n";
- }
-