Want to Track Modem Usage on SPARCStation *OR* this month's stupid question in Sun-Managers

2007-12-25 7:30:00

As the title indicates, this question probably wins this month's prize for

the dumbest one asked in Sun-Managers. Hopefully, the shell/awk script I

wrote will somewhat redeem myself. The original post:

   Here's another (I hope) easy one. I am interested in tracking modem usage

                           ^^^^ was it ever

   on our Sun SPARCStations, SunOS4.1.1. We don't run accounting, but logins

   are recorded in /var/adm/wtmp and the modem is on port ttya. One can simply

   say who /var/adm/wtmp to get a listing of logins, and then of course,

   pipe that through grep ttya to determine modem usage.

   What I would like to do is determine how long people have been on - i.e. one

   needs to match up the login time with the logout time. Because there's only

   a single modem (for now!) on ttya, this isn't too tough. However, being the

   overworked (OK, and a little lazy:-) sysadmin, I'm *sure* someone has written

                                ^^^^ and perhaps a little brain-dead! ;-)

   a shell/awk/whatever (we don't have perl though) script to do this.

   Can someone help me? (Or suggest a better approach)

   I will, of course, summarize (wasn't this discussed somewhere a while ago?)

   P.S. Re: Today's Wall Street Journal. Sun announces plans to support Intel

        architectures with SunOS/OW/NFS/etc. by mid-92. Interesting ...

> Some interesting responses to this. Basically, some concerns about Sun

> splitting their resources to go after MicroSoft and the PC market, rather

> than furthering SPARC (but perhaps this is in indication that there are

> problems in speeding up SPARC - where's the 80MHz machine?).

> Some not-so-happy 386i owners question Sun's committment.

> Finally, I personally think Sun is biting off a huge project, but if they

> are successful, they may become the dominent computer *software* (ala MS)

> company of the 90's. I think SPARC/UNIX/NFS/ONC/etc. could eventually pass

> up PC/DOS/OS2/whatever, but I can understand McNealy's impatience.

> Yep, this is somewhat inappropriate discussion for Sun-Managers, but I thought

> I would pass this info on to an interested & knowledgeable group.

> Followups to {alt,comp}.sys.sun

A zillion of you said (of course) use last(1). No excuses here ladies & gents,

I just did not know about this. In my sorry defense, let me say that I *did*

look through the related man pages; it appears that last is not cross-referenced

anywhere except lastcomm and, of course, List(1) [shoulda looked! :-( ]

I was interested in a summary report, so I ended up writing the following:

#!/bin/csh

# Original from (c) copyright CWI, Frank Kuiper Amsterdam, June 19, 1991

# Substansial modification by alek, 9/91

# Provide more summary information, and maybe redeems one for a dumb question

set term = a

if ( "$1" == "all" ) set term = ""

echo " User #logins First Login Last Login Time" ; echo ""

# if all, need to grep out network tty's & ftp's - they mess up field order

last $term | grep -v ttyp | grep -v ftp | \

 nawk '{if (n[$1]=="") l[$1]=$4" "$5" "$6;n[$1]+=1;f[$1]=$4" "$5" "$6;t[$1]=$9;\

   h=substr($9,2,2); h1[$1]=h1[$1]+h ; m=substr($9,5,2) ; m1[$1]=m1[$1]+m } \

   END {for (u in n) { if( u!="wtmp" && u!="") \

   { h2[u] = int(m1[u]/60); m2[u]=m1[u]-60*h2[u]; h2[u]=h2[u]+h1[u]; \

   printf "%8s %7d %16s %14s %5s:%s\n", u,n[u],f[u],l[u],h2[u],m2[u]; \

   h3=h3+h2[u];m3=m3+m2[u];n4=n4+n[u]}} h4=int(m3/60);m4=m3-60*h4; h4=h4+h3; \

   printf "%8s %7d %16s %14s %5s:%s\n", "Total",n4,"","",h4,m4 }' | \

 sort -n +1

exit

[ (shortened) output looks like]

    User #logins First Login Last Login Time

     jmb 4 Sep 2 14:08 Sep 5 02:25 7:23

     sgl 7 Aug 30 08:33 Sep 4 07:51 1:50

    alek 10 Aug 29 13:00 Sep 5 23:12 0:39

     cwr 12 Aug 30 01:44 Sep 6 03:20 46:20

   Total 33 56:12

Let me close by truly thanking everyone that responded to a "dumb" question

with overall polite answers (only two RTFM's, and one copy of the man page).

I hope some of you find the shell/awk script helpful.

Alek Komarnitsky 303-449-0649

Software Tools Manager, Spatial Technology, Inc. 2425 55th Street, Bldg A

alek@spatial.com Boulder, CO 80301-5704

The Hall of Fame is:

Frank Kuiper <frankk@cwi.nl> sent me the following shell/awk script that

got me thinking about this:

#!/bin/sh

#set -x

#

# (c) copyright CWI, Frank Kuiper

# Amsterdam, June 19, 1991

#

# usage: logus [-a|console|tty?|user-name|month]

term=${1-console}

if [ "$term" = "-a" ] ; then

        last | \

        awk '{x[NR]=$0}END{for (i=NR; i>0; i--) print x[i]}'| \

        awk '{l[$1]+=1; ll[$1]=$4" "$5" "$6" "$7} \

                END{for (i in l) printf "%8s %4d %s\n", i, l[i], ll[i]}' | \

        sort -rn +1

else

        last | \

        awk '{x[NR]=$0}END{for (i=NR; i>0; i--) print x[i]}'| \

        grep -i $term | \

        awk '{l[$1]+=1; ll[$1]=$4" "$5" "$6" "$7} \

                END{for (i in l) printf "%8s %4d %s\n", i, l[i], ll[i]}' | \

        sort -rn +1

fi

Also kudo's to Claus Assmann <ca@idefix.informatik.uni-kiel.dbp.de> for

some other interesting looking scripts/programs that I didn't happen to use.

And thanx to all the others that responded

dj@astro.lsa.umich.edu diab jerius

david@srv.pacbell.com (David St. Pierre)

stern@sunne.east.sun.com (Hal Stern - Consultant)

steve@icad.com Steve Carr

rick%pgt1@Princeton.EDU (Rick Mott)

wallen@cogsci.UCSD.EDU (Mark R. Wallen)

simon@aus.sun.com (Simon Woodhead - Technical Consultant)

kevins@aus.sun.com (Kevin Sheehan {Consulting Poster Child})

Rhod Davies <rhod@computer-science.manchester.ac.uk>

"Fuat C. Baran" <fuat@cunixf.cc.columbia.edu>

Peter Lamb (prl@iis.ethz.ch)

mp@allegra.att.com (Mark Plotnick)

Mike Raffety <miker@sbcoc.com>

John Hasley<hasley@andy.bgsu.edu>

shipley@kizmiaz.tcs.com

mikulska@ece.UCSD.EDU (Margaret Mikulska)

alexl@daemon.cna.tek.com (alex;923-4483)

bks@okeeffe.CS.Berkeley.EDU (Brian K. Shiratsuki)

dal@gcm.com (Dan Lorenzini)

keves@meaddata.com (Brian Keves - Consultant)

Richard Niziak <ontologic!gremlin!rickn@uu.psi.com>

ssigv!lewis@uunet.UU.NET (Don Lewis)

gatech!jtsv16.jts.com!gerry@ico.isc.com (G. Roderick Singleton )

pag@scg.boulder.co.us (Peter Gross)

bchivers@smiley.mitre.org (Brent Chivers)

Comments

Got something to say?

You must be logged in to post a comment.