[comp.sources.wanted] Searching the output of last

guru@buhub.bradley.edu (Jerry Whelan) (04/28/91)

	Does anyone have/know of a program to parse the output of the
'last' command and tell me who was logged in at some arbitrary time?
I'd like to be able to type: 

			whenwho 9:56

and get a list of all the people who were logged in during that particular
minute.  My site resets the wtmp file at 4 AM, so we are not dealing with
infinite output from 'last.'  Awk, perl, C or anything that works reasonably
quickly is fine with me.

-------------------------------------------------------------------------------
	"I'm not sure what I mean, so I'm going to listen to what I say."
 guru@ (buhub.bradley.edu || bucc1.bradley.edu) || whelan@wiliki.eng.hawaii.edu

navarra@casbah.acns.nwu.edu (John 'tms' Navarra) (04/29/91)

In article <1991Apr28.070748.5279@bradley.bradley.edu> guru@buhub.bradley.edu (Jerry Whelan) writes:
>
>	Does anyone have/know of a program to parse the output of the
>'last' command and tell me who was logged in at some arbitrary time?
>I'd like to be able to type: 
>
> 			whenwho 9:56

         do last | grep time  
                  
>
>and get a list of all the people who were logged in during that particular
>minute.  My site resets the wtmp file at 4 AM, so we are not dealing with
>infinite output from 'last.'  Awk, perl, C or anything that works reasonably
>quickly is fine with me.
>
>-------------------------------------------------------------------------------
>	"I'm not sure what I mean, so I'm going to listen to what I say."
> guru@ (buhub.bradley.edu || bucc1.bradley.edu) || whelan@wiliki.eng.hawaii.edu


-- 
From the Lab of the MaD ScIenTiST:
      
navarra@casbah.acns.nwu.edu

jik@athena.mit.edu (Jonathan I. Kamens) (04/29/91)

In article <1991Apr29.021236.12132@casbah.acns.nwu.edu>, navarra@casbah.acns.nwu.edu (John 'tms' Navarra) writes:
|> In article <1991Apr28.070748.5279@bradley.bradley.edu> guru@buhub.bradley.edu (Jerry Whelan) writes:
|> >	Does anyone have/know of a program to parse the output of the
|> >'last' command and tell me who was logged in at some arbitrary time?
|> >I'd like to be able to type: 
|> >
|> > 			whenwho 9:56
|> 
|>          do last | grep time  

  I want to be polite, but I have an overwhelming urge to respond to this by
saying, "Get a clue."

  Mr. Whelan wants to know how to find out who was logged in at any particular
time, not who logged in or logged out at any particular time.

  The output of "last" indicates only the time a user logged in, and the time
he/she logged out.  Therefore, grepping for a particular time will catch only
the people who logged in or logged out during that minute.

  In order to do what Mr. Whelan wants, you need a utility that reads the
output of last (or reads /usr/adm/wtmp directly) and checks each pair of login
and logout times to see if the specified time is between them.

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik@Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710

cliff@demon.co.uk (Cliff Stanford) (04/30/91)

In article <1991Apr28.070748.5279@bradley.bradley.edu> guru@buhub.bradley.edu (Jerry Whelan) writes:
>
>	Does anyone have/know of a program to parse the output of the
>'last' command and tell me who was logged in at some arbitrary time?
>I'd like to be able to type: 
>
>			whenwho 9:56
>
>and get a list of all the people who were logged in during that particular
>minute.  My site resets the wtmp file at 4 AM, so we are not dealing with
>infinite output from 'last.'  Awk, perl, C or anything that works reasonably
>quickly is fine with me.

	I just knoked the following up.  Don't blame me if it's
full of bugs or non-prtable.  It works for me!
		Cliff.

#!/bin/sh
# whenwho
last | gawk -v wanted=$1 '
BEGIN	{
		wmin = whr = wanted
		sub(/.*:/, "", wmin)
		sub(/:.*/, "", whr)
		}

FNR==1	{ next }

		{
		min = hr = $8
		sub(/.*:/, "", min)
		sub(/:.*/, "", hr)
		if (hr < whr)
			next
		if (hr == whr && min < wmin)
			next
		if (hr > whr && min > wmin)
			next
		emin = ehr = $9
		sub(/.*:/, "", emin)
		sub(/:.*/, "", ehr)
		hr += ehr
		min += emin
		if (min > 59)
			{
			hr++
			min -= 60
			}
		if (hr < whr)
			next
		if (hr == whr && min < wmin)
			next
		print $1
		}
' | sort | uniq
-- 
Cliff Stanford				Email:	cliff@demon.co.uk (Work)
Demon Systems Limited				cms@demon.co.uk   (Home)
42 Hendon Lane				Phone:	081-349 0063	  (Office)
London	N3 1TT	England				0860 375870	  (Mobile)