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! |
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) |
u can use the 'last' and 'lastb ' command also
|
Thanks for the info guys!
|
All times are GMT -5. The time now is 09:34 PM. |