Skip to content

Instantly share code, notes, and snippets.

@mperlet
Last active December 26, 2015 03:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mperlet/7085436 to your computer and use it in GitHub Desktop.
Save mperlet/7085436 to your computer and use it in GitHub Desktop.
Shows System Uptime
function show_ut {
last -F $USER |
grep ":0 .* :0" |
sed 's/\s\s*/ /g' |
cut -d" " -f4-15 |
grep $(LANG=en_US date "+%b") |
grep -v "(00:00)"
asd=$(last -F $USER |
grep ":0 .* :0" |
sed 's/\s\s*/ /g' |
grep $(LANG=en_US date "+%b") |
awk '{ print $NF }' |
grep -v "(00:00)" |
grep -o "[0-9]\+:[0-9]\+")
counter=0
for i in $asd
do
minutes=$(echo $i | awk -F: '{ print ($1 * 60) + $2 }')
counter=$(expr $counter + $minutes)
done
((hour=$counter/60))
((min=$counter-$hour*60))
h=$(printf "%.2i\n" $hour)
m=$(printf "%.2i\n" $min)
echo =================
echo Finally: $h:$m
}
# Example
# [user@mashine ~]$ show_ut
# Wed Oct 23 10:59:53 2013 - Wed Oct 23 14:55:22 2013 (03:55)
# Mon Oct 21 13:54:56 2013 - Mon Oct 21 17:37:16 2013 (03:42)
# Mon Oct 21 13:13:10 2013 - Mon Oct 21 13:54:45 2013 (00:41)
# Wed Oct 16 09:24:07 2013 - Wed Oct 16 16:43:55 2013 (07:19)
# Thu Oct 10 09:50:17 2013 - Thu Oct 10 12:27:32 2013 (02:37)
# Thu Oct 10 09:48:13 2013 - Thu Oct 10 09:50:09 2013 (00:01)
# Tue Oct 8 12:47:36 2013 - Tue Oct 8 17:06:13 2013 (04:18)
# Mon Oct 7 10:24:32 2013 - Mon Oct 7 17:35:38 2013 (07:11)
# Wed Oct 2 09:31:33 2013 - Wed Oct 2 11:56:19 2013 (02:24)
# Tue Oct 1 12:05:10 2013 - Tue Oct 1 17:09:41 2013 (05:04)
# =================
# Finally: 37:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment