Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 05-07-2003, 03:31 PM   #1
Registered: Apr 2003
Location: Waterford, Ireland
Distribution: Mandrivia 2006.1, Ubuntu 7.10
Posts: 188

Rep: Reputation: 30
strange request: script to track logged in time

Hi !

I'm having great fun with writing basic bash scripts. It's amazing how specific you can make 'em. I was wondering if anyone could suggest an efficient/reliable way "to keep track of the accumulated time that a user is logged in since the system was set up".

Basically I was think of using the "last" command and using a script to extract the times but this seems unreliable and messy. Another one is to extract the login time and logoff time and add to an accumulating time tracking file.

Just wondering if anyone has other ways of doing this. Thanks!

Last edited by hamster; 05-07-2003 at 03:37 PM.
Old 05-08-2003, 12:58 AM   #2
Registered: Jan 2003
Posts: 167

Rep: Reputation: 30
I've never seen that command before... it's pretty neat.

Something you might want to try is to log the time when a user logs in to a variable, and then subtract that from the current time when they log out, and save that difference in a file somwhere (well, add the difference to the value that is already in that file)

check out the 'expr' command (or use '| bc' ) to do the math.

This can be done from the .bash_profile/.bash_logout files. You can get the time from a number of commands, I used 'date' here:

$ date | sed 's/.* \([0-9]*:[0-9]*:[0-9]*\).*/\1/'

I'm sure there's a bunch of cool options to the 'date' command that will make the format easier for you (absolute time would be nice so that you don't have to worry about the time rolling over @ midnight)
Old 05-08-2003, 01:19 AM   #3
Registered: Feb 2002
Location: India
Distribution: Slacky 12.1, XP
Posts: 992

Rep: Reputation: 30
u can use the 'last' and 'lastb ' command also
Old 05-08-2003, 01:52 PM   #4
Registered: Apr 2003
Location: Waterford, Ireland
Distribution: Mandrivia 2006.1, Ubuntu 7.10
Posts: 188

Original Poster
Rep: Reputation: 30
Thanks for the info guys!


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
apache track incoming, outgoing requests real-time dtra Linux - Networking 1 07-18-2005 08:19 AM
Audacity 1.1.2-3.1 strange distortion when more than one track is recorded MMRush Linux - Software 0 05-08-2005 06:00 AM
shell script to calculate the time a user is logged in racer_mec Linux - Newbie 2 02-08-2005 12:40 PM
displaying last time you logged on in fedora Core 1 m80arm Linux - General 0 04-22-2004 04:15 PM
Security question, strange packet in apache request INFINYT9 Linux - Security 5 04-02-2004 11:43 AM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:42 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration