#!/bin/bash
# uptime.sh
# get uptime from /proc/uptime
uptime=$(</proc/uptime)
uptime=${uptime%%.*}
seconds=$(( uptime%60 ))
minutes=$(( uptime/60%60 ))
hours=$(( uptime/60/60%24 ))
days=$(( uptime/60/60/24 ))
echo "$days days, $hours hours, $minutes minutes, $seconds seconds"
Ofcourse in the same way you could add months, years, decades etc.
you got the idea.
2 comments:
Wow, very simple and elegant. Thank you!
I just use "uptime" command...
Post a Comment