Operating System - HP-UX
1833187 Members
3128 Online
110051 Solutions
New Discussion

logging the amount of time a user is logged in

 
SOLVED
Go to solution
Allan Pincus
Frequent Advisor

logging the amount of time a user is logged in

All,

Is there a utility that already exists that allows me to track the amount of time a user is logged into a system over a given period of time?

Thanks!
7 REPLIES 7
Paula J Frazer-Campbell
Honored Contributor
Solution

Re: logging the amount of time a user is logged in

Hi

Have alook at last command - man last.

e.g.

mend pts/ta Wed Sep 18 08:18 - 12:04 (03:46)
mend pts/ta Tue Sep 17 17:33 - 17:51 (00:17)
mend pts/ta Tue Sep 17 17:19 - 17:21 (00:01)
mend pts/ta Tue Sep 17 10:06 - 17:15 (07:09)
mend pts/td Mon Sep 16 12:03 - 18:22 (06:18)
mend pts/tc Mon Sep 16 11:30 - 16:29 (04:58)
mend pts/ta Mon Sep 16 09:11 - 16:29 (07:17)
mend pts/tb Fri Sep 13 09:22 - 10:04 (00:41)
mend pts/tb Fri Sep 13 09:14 - 09:22 (00:08)
mend pts/tc Thu Sep 12 12:10 - 17:22 (05:12)


paula
If you can spell SysAdmin then you is one - anon
James R. Ferguson
Acclaimed Contributor

Re: logging the amount of time a user is logged in

Hi:

If '/var/adm/wtmp' isn't present, create it:

# touch /var/adm/wtmp
# chmod 644 /var/adm/wtmp

Now you can use :

# last
# last username

Regards!

...JRF...
Allan Pincus
Frequent Advisor

Re: logging the amount of time a user is logged in

This is great, guys. Now, is there a convenient way for me to accumulate the time in a given day, or do I have to create my own script; i.e., is there a utility that already does this so I don't have to reinvent the wheel?

(Don't write any scripts here, I can do that, I'm just trying to avoid the hassle).

Thanks!
Darren Prior
Honored Contributor

Re: logging the amount of time a user is logged in

Hi Allan,

I think this is the point where you'll need to start script writing. As well as the output of last, you may also find the fwtmp(1M) command useful (or perhaps use the info in the utmp(4) man page if you feel like writing a C program from scratch to read/calculate the file.)

regards,

Darren.
Calm down. It's only ones and zeros...
Allan Pincus
Frequent Advisor

Re: logging the amount of time a user is logged in

Is there a convenient way to do a date coversion to seconds from the epoch without having to parse the date string; i.e, can I pass the date arguement from wtmp to the date command and return number of seconds?
Darren Prior
Honored Contributor

Re: logging the amount of time a user is logged in

Hi Allan,

This sounds like an ideal application for A Clay Stephenson's datehammer. Just search for caljd on the forums for some of the many uses it has been put to.

regards,

Darren.
Calm down. It's only ones and zeros...
Steven Sim Kok Leong
Honored Contributor

Re: logging the amount of time a user is logged in

Hi,

Merijn has kept a link to A. Clay Stephenson's Date Hammer (of both shell and perl versions) at the end of his page:

https://www.beepz.com/personal/merijn/

Hope this helps. Regards.

Steven Sim Kok Leong