Plan 9 from Bell Labs’s /usr/web/sources/contrib/steve/rc/lastlog

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#!/bin/rc
#
#	last login of user,
#	with an arg it prints only matching entries.
#

rfork e

rd=cat
if (! ~ $#* 0)
	rd=(grep ' ' ^$"*)

cat /sys/log/auth |
	$rd  |
	awk '
	$5=="tr-ok" && $NF ~ ".*@bootes"{
		uid = $NF;
		gsub("@.*$", "", uid);
		last[uid] = $2 " " $3 " " $4;
		gsub(":[0-9][0-9]$", "", last[uid]);
		ip = $6;
		gsub("^.*\\(", "", ip);
		gsub("\\).*$", "", ip);
		from[uid] = ip;
	}
	END{ 
		cmd = "ls -ltu /usr/*/lib/profile";
		while(cmd | getline){
			uid = $NF;
			gsub("^.*/usr/", "", uid);
			gsub("/lib/profile$", "", uid);
			if(last[uid] == "")
				last[uid] = $7 " " $8 " " $9;
		}
		close(cmd);	 
		for(i in last)
			printf("%-20s %-16s %s\n", i, last[i], from[i]);
	}
	'

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.