0

I am writing a script to display how long a user has been logged in.

who | grep "$userid" | awk '{print $1,$3,$4}' | while read user time; do \echo $(($(($(date +%s) - $(date -d "$time" +%s)))/60)) minutes; done

How can I make this display hours and minutes? As of now it only displays minutes. I need it to display, for example, 1 hour(s) and 45 minute(s) with the (s) included.

0

Using GNU date

who | grep "$userid" | awk '{print $1,$3,$4}' | while read user time; do echo -n "$user  ";eval "echo $(date -ud "@$(($(($(date +%s) - $(date -d "$time" +%s)))))" +'$((%s/3600/24)) days %H hours %M minutes %S seconds')"; done  

Courtesy : Displaying seconds as days/hours/mins/seconds?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.