hi, I need to know how long a user is connected to the server, so at any time I can tell how many hours he was connected since a given date.
as far as I got was to get the date the user logged in and the date he got out. I put this on the .logout file, so I get two lines (login date/time and logout date/time) everytime the user connects. this is just the output of the `who am i` command and the date the user exists the system, but I have no clue of how to calculate the time between these two dates. any help please??
Try using the last command. When you use it, you get who logged in, where they logged in from, when the logged in, when they logged out, and for how long they were logged in. If they were logged in for five minutes, the last column would be (00:05). If they were logged in for an hour and five minutes, the last column would be (01:05). If they were logged in for a day and five minutes, you would see (1+00:05).
Of course, used with grep, you can pull out just a given user, and not get the entire list of folk. You'll need a parser, or an awk script to pull the data out and give you an actual time though, and unfortunately, I don't have the time to do it just now (meetings ... blah), but will see what I can get if no one else gets to it first.