[comp.lang.perl] an example please

parker@ohstpy.mps.ohio-state.edu (11/07/90)

Could someone send me a perl script that reads /etc/utmp file
under SusOS 4.1 as an example.

If possible please send me it E-mail as well as posting it,
my E-mail address is:
parker@hydrogen.mps.ohio-state.edu


Thanks.

composer@chem.bu.edu (Jeff Kellem) (11/08/90)

In article <9013.2737e4c1@ohstpy.mps.ohio-state.edu> parker@ohstpy.mps.ohio-state.edu writes:

   Date: 7 Nov 90 15:41:05 GMT

   Could someone send me a perl script that reads /etc/utmp file
   under SusOS 4.1 as an example.

If the PERL source is installed in the PERL_DIR directory tree, then look in
PERL_DIR/eg/who.  It's basically a replacement for the who program.  That
should give you enough to go on.

Enjoy...

			-jeff

Jeff Kellem
Internet: composer@chem.bu.edu

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (11/08/90)

In article <9013.2737e4c1@ohstpy.mps.ohio-state.edu> parker@ohstpy.mps.ohio-state.edu writes:
: Could someone send me a perl script that reads /etc/utmp file
: under SusOS 4.1 as an example.

Here's a who clone:

#!/usr/bin/perl
# This assumes your /etc/utmp file looks like ours
open(UTMP,'/etc/utmp');
@mo = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec);
while (read(UTMP,$utmp,36)) {
    ($line,$name,$host,$time) = unpack('A8A8A16l',$utmp);
    if ($name) {
	$host = "($host)" if $host;
	($sec,$min,$hour,$mday,$mon) = localtime($time);
	printf "%-9s%-8s%s %2d %02d:%02d   %s\n",
	  $name,$line,$mo[$mon],$mday,$hour,$min,$host;
    }
}   

Larry