home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!caen!sol.ctr.columbia.edu!eff!ckd
- From: ckd@eff.org (Christopher Davis)
- Subject: another semi-useful 10-minute hack
- Message-ID: <CKD.92Aug14120200@loiosh.eff.org>
- Sender: usenet@eff.org (NNTP News Poster)
- Nntp-Posting-Host: loiosh.eff.org
- Organization: Electronic Frontier Foundation Tech Central
- Date: Fri, 14 Aug 1992 16:02:02 GMT
- Lines: 39
-
- This is just another perlvangelistic posting showing how you can easily
- toss together a bit of perl code to do something useful.
-
- this will print the lastlog entry for a user, or you if you don't specify.
-
- took about 10 minutes; the main "problem" was a typo ($llty for $lltty)
- which -w caught nicely.
-
- #!/usr/bin/perl -- # -*- Perl -*-
-
- # based on lastlog.h, so change it if you must
- # assumes Sun format, time_t is a 4byte long, line is 8 chars, host is 16 chars
- # should use c2ph or something to do this right, it's a hack
- require 'ctime.pl';
-
- $lastlogfile = "/usr/adm/lastlog";
- $lastlogfmt = "La8a16";
- $lastlogsize = 28;
-
- $username = shift(@ARGV) || getlogin;
- $userid = (getpwnam($username))[2];
-
- open(LASTLOG,"<$lastlogfile");
-
- seek(LASTLOG,$lastlogsize*$userid,0);
-
- read(LASTLOG,$lastlogentry,$lastlogsize);
-
- ($lltime,$lltty,$llhost) = unpack($lastlogfmt,$lastlogentry);
-
- chop($lldate = &ctime($lltime));
-
- print "last login for $username: $lldate on line $lltty";
- print " from host $llhost" if $llhost;
- print "\n";
- --
- Christopher Davis * ckd@eff.org * System Administrator, EFF * +1 617 864 0665
- ``Ed Gruberman, you fail to grasp Ti Kwan Leep.
- Approach me that you might see.'' -- The Master
-