File: last-log.pl

package info (click to toggle)
emacspeak 29.0-9
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 12,904 kB
  • sloc: xml: 55,354; lisp: 48,335; cpp: 2,321; tcl: 1,500; makefile: 936; python: 836; sh: 785; perl: 459; ansic: 241
file content (30 lines) | stat: -rwxr-xr-x 902 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/perl -w
#$Id: last-log.pl 5697 2008-07-20 17:21:38Z tv.raman.tv $
#Description: Print out hostname wher ewe logged in from:
use strict;
#see /usr/include/utmp.h
use constant  RECORD_SIZE => 292;
use constant RECORD_FORMAT =>'l A32 A256';
my $CONSOLE_SND  = 'play /usr/share/sounds/startup3.wav';
my $user = shift;
$user ||= $ENV{LOGNAME};
my $u =qx(id -u);
die "User $user not found on this system" unless defined ($u);
chomp($u);

my $lastlog  = "/var/log/lastlog";
open(LASTL, $lastlog) or die "Cannot read lastlog $!";
my $offset = $u * RECORD_SIZE  ;
seek (LASTL, $offset, 0);
my $record;
read(LASTL, $record, RECORD_SIZE);
my ($time, $line, $host) = unpack(RECORD_FORMAT, $record);
if ( $host) {
my $home=$ENV{HOME};
open (OUT, "> $home/.emacspeak/.current-remote-hostname") or die "Cannot write output $!";
print OUT $host, "\n";
close OUT;
} else {
  qx($CONSOLE_SND);
}
close LASTL;