Skip to content

Instantly share code, notes, and snippets.

@mrzlodey
Created September 23, 2015 13:38
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 mrzlodey/f5dd546d09605677cf54 to your computer and use it in GitHub Desktop.
Save mrzlodey/f5dd546d09605677cf54 to your computer and use it in GitHub Desktop.
SystemMountPoint="/";
LinesPrefix=" ";
b=$(tput bold); n=$(tput sgr0);
SystemLoad=$(cat /proc/loadavg | cut -d" " -f1);
ProcessesCount=$(cat /proc/loadavg | cut -d"/" -f2 | cut -d" " -f1);
MountPointInfo=$(/bin/df -Th $SystemMountPoint 2>/dev/null | tail -n 1);
MountPointFreeSpace=( \
$(echo $MountPointInfo | awk '{ print $6 }') \
$(echo $MountPointInfo | awk '{ print $3 }') \
);
UsersOnlineCount=$(users | wc -w);
UsedRAMsize=$(free | awk 'FNR == 3 {printf("%.0f", $3/($3+$4)*100);}');
SystemUptime=$(uptime | sed 's/.*up \([^,]*\), .*/\1/');
if [ ! -z "${LinesPrefix}" ] && [ ! -z "${SystemLoad}" ]; then
echo -e "${LinesPrefix}${b}System load:${n}\t${SystemLoad}\t\t\t${LinesPrefix}${b}Processes:${n}\t\t${ProcessesCount}";
fi;
if [ ! -z "${MountPointFreeSpace[0]}" ] && [ ! -z "${MountPointFreeSpace[1]}" ]; then
echo -ne "${LinesPrefix}${b}Usage of $SystemMountPoint:${n}\t${MountPointFreeSpace[0]} of ${MountPointFreeSpace[1]}\t\t";
fi;
echo -e "${LinesPrefix}${b}Users logged in:${n}\t${UsersOnlineCount}";
if [ ! -z "${UsedRAMsize}" ]; then
echo -ne "${LinesPrefix}${b}Memory usage:${n}\t${UsedRAMsize}%\t\t\t";
fi;
echo -e "${LinesPrefix}${b}System uptime:${n}\t${SystemUptime}";
@MrDimarius
Copy link

MrDimarius commented Feb 25, 2021

15 line better
UsedRAMsize=$(free | grep Mem| awk '{printf("%.0f", $3/($2)*100);}');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment