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.

Derek
  • 11
  • 5

1 Answers1

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?