dotfiles/dotlocal/bin/newuptime

27 lines
596 B
Text
Raw Permalink Normal View History

2024-07-20 22:10:54 +02:00
#!/bin/sh
# Always print uptime in three columns.
# Two case; case time < 1d, print h m s
# case time > 1d, print d h m
time=$(cat /proc/uptime)
time="${time%%.*}"
if [ ${time} -ge 86400 ]
then
day=$(($time / 86400))
time=$((${time} - day * 86400))
hour=$(($time / 3600))
time=$(($time - hour * 3600))
minutes=$(($time / 60))
time=$((time - minutes * 60))
echo "${day}d ${hour}h ${minutes}m"
else
hour=$(($time / 3600))
time=$(($time - hour * 3600))
minutes=$(($time / 60))
time=$((time - minutes * 60))
echo "${hour}h ${minutes}m ${time}s"
fi