LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 05-07-2003, 02:31 PM   #1
hamster
Member
 
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 02:37 PM.
 
Old 05-07-2003, 11:58 PM   #2
PTBmilo
Member
 
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/'
14:49:31

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, 12:19 AM   #3
jayakrishnan
Member
 
Registered: Feb 2002
Location: India
Distribution: Slacky 12.1, XP
Posts: 991

Rep: Reputation: 30
u can use the 'last' and 'lastb ' command also
 
Old 05-08-2003, 12:52 PM   #4
hamster
Member
 
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!
 
  


Reply


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 07:19 AM
Audacity 1.1.2-3.1 strange distortion when more than one track is recorded MMRush Linux - Software 0 05-08-2005 05:00 AM
shell script to calculate the time a user is logged in racer_mec Linux - Newbie 2 02-08-2005 11:40 AM
displaying last time you logged on in fedora Core 1 m80arm Linux - General 0 04-22-2004 03:15 PM
Security question, strange packet in apache request INFINYT9 Linux - Security 5 04-02-2004 10:43 AM


All times are GMT -5. The time now is 05:18 PM.

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