home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zephyr.ens.tek.com!uw-beaver!micro-heart-of-gold.mit.edu!rutgers!usc!zaphod.mps.ohio-state.edu!mips!spool.mu.edu!news.cs.indiana.edu!nstn.ns.ca!morgan.ucs.mun.ca!csd.unb.ca!jaf
- From: jaf@jupiter.sun.csd.unb.ca (J Anthony Fitzgerald)
- Newsgroups: comp.lang.perl
- Subject: print and write display different results
- Message-ID: <1992Jul26.155523.12416@jupiter.sun.csd.unb.ca>
- Date: 26 Jul 92 15:55:23 GMT
- Distribution: na
- Organization: University of New Brunswick
- Lines: 58
-
- Running perl 4.035 on SunOS 4.1.2, I am trying to extract the name of
- the system from which a user last logged in and print it in a report.
- The script and a sample output are enclosed below. The script seems to
- be able to extract the value that I want and will print it out when I
- use a print statement, however, when I use a write statement, the value
- is not printed. Any suggestions?
-
- ============================ start enclosure
- #!/usr/local/bin/perl
- # Process list of compromised accounts and lock same
-
- require "getopts.pl";
- &Getopts( "tld:P:" );
- $test=defined $opt_t;
-
- open( PWD, "ypcat passwd |" ) || die "can't ypcat passwd: $!\n";
- while( <PWD> ) { $pass{(split(/:/))[0]}= $_; }
- close( PWD );
-
- open( LOG, "< /var/adm/lastlog" ) || die "can't open lastlog: $!\n";
- foreach $lid ( @ARGV ) {
- if( $lid=~ /^\d+$/ ) {
- $uid= $lid;
- } else {
- ( $uid,$gcos )= ( split( ':', $pass{$lid} ) )[ 2,4 ];
- }
- if( seek( LOG, $uid*28, 0 ) ){}
- sysread( LOG, $lastlog, 28 );
- ( $ltime, $lport, $llfrom )= unpack( "la5A*", $lastlog );
- ( $ly, $lmo, $lda )= (localtime($ltime))[ 5,4,3 ];
- if( $ltime ) {
- ( $llda= sprintf( "%2d%2d%2d", $ly, 1+$lmo, $lda ) )=~ tr/ /0/;
- $llog= $llda;
- $llog.= "@${llfrom}" if $llfrom;
- } else { $llog= ""; }
- write;
- print "test: $llfrom $lport $llog\n";
- }
- close( LOG );
-
- format STDOUT_TOP =
- loginid lastlog Name, etc.
- ======== =========================== =============================
- .
- format STDOUT =
- @<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- $lid, $llog, $gcos
- .
- ================================ sample output of script
- loginid lastlog Name, etc.
- ======== =========================== =============================
- mikes 920725@ Mike Sprague Dept. Environmen
- test: milton.u.washing ttyp0 920725@milton.u.washing
- ================================ end enclosures
- --
- J. Anthony Fitzgerald jaf@UNB.ca (506) 453-4573
- Computing Services UofNB Box 4400 (506) 453-3590 (FAX)
- Fredericton, NB, CANADA, E3B 5A3
-