add newuptime

This commit is contained in:
primardj 2024-03-24 23:37:18 +00:00
parent bd34aeeeca
commit 42a6b8052c

26
newuptime Executable file
View file

@ -0,0 +1,26 @@
#!/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