Last active
August 11, 2022 23:39
-
-
Save anselmobd/8a3b4eca0dcebe581ec8a7f756383ce0 to your computer and use it in GitHub Desktop.
Better uptime to log (compact and standardized)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ ! -f $0.pkgchkok ] ; then | |
PKG_OK=$(dpkg-query -W --showformat='${Status}\n' bc 2> /dev/null |grep "install ok installed") | |
if [ "" = "$PKG_OK" ] ; then | |
echo "Required 'bc' package not installed" | |
exit 1 | |
else | |
touch $0.pkgchkok | |
fi | |
fi | |
DATE="$(date +"%y/%m/%d %a %H:%M:%S")" | |
UPTIME="$(echo "scale=0 | |
upsecs=$(cat /proc/uptime | cut -d" " -f1)/1 | |
updays=upsecs/60/60/24 | |
updaysecs=upsecs-updays*60*60*24 | |
uphours=updaysecs/60/60 | |
upmins=updaysecs/60-uphours*60 | |
print updays | |
print \"D \" | |
print uphours | |
print \"H \" | |
print upmins | |
print \"M\" | |
" | bc)" | |
USERS="$(who | wc -l)" | |
LA="$(cat /proc/loadavg | cut -d" " -f-3)" | |
echo "${DATE} ${UPTIME} ${USERS}U ${LA}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Required utility: (not installed by default on minimal Debian)
This script output samples:
"uptime" command output samples: