Skip to content

Instantly share code, notes, and snippets.

@mathieu-aubin
Last active November 12, 2018 06:29
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mathieu-aubin/06673823e79f201fd2f8858f5aa3e581 to your computer and use it in GitHub Desktop.
Bash QuickStats
#!/bin/bash
#
# qstats (bash QuickStats)
#
# Copyright 2017 Mathieu Aubin <mathieu@zeroserieux.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
_dT=$(date +"%Y-%m-%d %H:%M:%S") ;
_tD=$(echo ${_dT} | cut -d' ' -f1) ;
_tT=$(echo ${_dT} | cut -d' ' -f2) ;
_eO="2>/dev/null" ;
_tmP=`getopt -o d --long debug -n 'qstats' -- "${@}"` ;
eval set -- "${_tmP}" ;
while true ; do
case "${1}" in
-d|--debug)
_eO="2>&1" ;
shift ;;
--)
shift ;
break ;;
*)
echo -e "\033[31mInternal error.\033[0m" ;
exit 1 ;;
esac
done
function _getDATA(){
_mI=$(/usr/bin/free -mh | grep Mem) ;
_mT=$(echo ${_mI} | awk '{print $2}') ;
_mU=$(echo ${_mI} | awk '{print $3}') ;
_uI=$(uptime | cut -d',' -f1 | grep -E -o "up.*" | sed -e 's/up//' -e 's/\ \ //g') ;
_displayDATA ;
}
function _displayDATA() {
echo -e "\n\033[1m[${_tD}] QUiCK STATS FOR:\033[0m \033[3m$(hostname)\033[0m\n" ;
echo -e "\033[1m [${_tT}] UPTiME iNFOS\033[0m" ;
echo -e "\033[1m Up:\033[0m ${_uI}" ;
echo -e "\033[1m [${_tT}] MEMORY iNFOS\033[0m" ;
echo -e "\033[1m Used :\033[0m ${_mU}" ;
echo -e "\033[1m Total:\033[0m ${_mT}\n" ;
}
eval _getDATA "${_eO}" ;
[[ "$?" -ge "1" ]] && echo -e "\033[31mAn error has ocurred.\033[0m" ;
unset _mI _mT _mU _uI _dT _tD _tT _eO ;
@mathieu-aubin
Copy link
Author

mathieu-aubin commented Apr 2, 2017

NOTE - Initial release had a typo error, mixup between memtotal and memused

Little QuickStats (qstats) i made on request.

Available on GitHub at:
https://gist.github.com/mathieu-aubin/06673823e79f201fd2f8858f5aa3e581

AsciiCast on Asciinema at:
https://asciinema.org/a/110338

Can be run straight from GitHub (using RAW url) like so:

bash <(curl -s https://gist.githubusercontent.com/mathieu-aubin/06673823e79f201fd2f8858f5aa3e581/raw/4f5687c93ce2eba03313304e2c97a029206da84f/qstats)

If somehow you get an error, use switches [-d|--debug] to view error message.

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