Looking for command to help with program
I need to be able to calculate the amount of time a user has been logged onto the system for.
UsrMin=$(who | grep $1 | cut -c30-35) Time=$(date +%H:%M) echo $UsrMin echo $Time echo LoginTime CurrentTime echo ' '$UsrMin - $Time ~ conntime f132a13 20:57 21:18 LoginTime CurrentTime 20:57 - 21:18 This is as close as I could get to figuring out my problem. It wouldn't allow me to do the subtraction so I left it like this. Please help! |
Extending that method, you'd convert the hrs to mins, add the extra mins, then subtract 'now' from 'then', optionally converting the result to hrs and mins if diff_result > 60.
Of course, this only works when the login time is in the same day as the current time. For a more general approach, you'd have to calc the date diff as well, probably using the various date format options. Personally, if this was for a serious eg prod system, I'd likely do it in Perl as it has plenty of date calc routines. |
All times are GMT -5. The time now is 10:05 PM. |