Bash Collection – Server Health Monitor for getting quick information of server status

The last three days, I’ve created a small bash script that outputs some important server health information. I’m using this script for displaying the server health on my Raspberry Pi at home. I’ll buy one of these official 7 inch touch screen displays for the Raspberry Pi and then show these health information on it.

Given the maximum values of some output variables, it also will change the colors of these values.

The usage of this script is simple: The main script lays on the server itself where it can get called via SSH each 2 seconds. On the raspberry pi there is just only a small script with a while true loop, that connects via SSH to the server and gets the output of that main script.

The main bash script needs some, mostly standard tools. If they are not already installed, they should be available through your package manager (apt-get install <packagename>)

  • lsb_release
  • mytop
  • ifstat
  • iotop
  • mpstat

The other tools are standard and should be already available:

  • uname
  • top
  • uptime
  • free

You need to add the following line to the “/etc/rc.local” on your server:

Please change the name of the interface (“em1”) according to your needs.

Next, copy and save the following script as /root/bin/monitoring.sh on your server:

Find the script here…

You may want to adjust or change some things in this script. For example in the lines 93 until 108 the maximum values (2nd parameter of function call “colorize”)

Note: This script was self written by me, Alex Löhner. It is still not really finished. You can see that at the end of the script. There are many placeholder lines. I’ll add other information to this script when I need them.

Save the script and make it executable:

You now already can call that script from your command line. It will output all the information needed to get the server status health.

You may want to create a monitor like me with a little Raspberry Pi and a 7″ touch screen monitor. For this, the user “pi” on the raspberry must be able to connect via SSH with your server without entering a password (Use SSH public key for this!).

Then save the following script on the raspberry and make it executable:

When running, the Pi should give you the output of the main script in your Pi Monitor.

See my monitor on the image below. 🙂



About Christin Löhner (Linux Counter)


  1. zenjive

    Cool script! However, it doesn’t seem to like the while loop for the CPU info:

    {c}: syntax error: operand expected (error token is “{c}”)

    • Alexander Löhner (Linux Counter)

      Unfortunatly the syntax highlighter doesn’t work properly here.

      In Lines 127, 134 and 138 there is a “{c}” without a “$” in front. This must be changed to look like this: “{c}”

      Edit: it is not the syntax highlight, it is a problem of wordpress itself.

  2. zenjive

    I’ve edited so it now looks like this:

    while true; do
    if [[ {c} -eq ${NUM_OF_CPU_CORES} ]]; then
    if [[ “${usage}” != “” ]]; then
    usage=”${usage} ”
    echo {cpus[{c}]}
    cpus[{c}]=$( colorize {cpus[{c}]} 10 )
    echo {cpus[{c}]}
    c=$(( {c} + 1 ))

    It still doesn’t like it. It spits this out at the beginning:

    (standard_in) 1: syntax error
    (standard_in) 1: syntax error
    (standard_in) 1: syntax error
    (standard_in) 1: syntax error

    ~ ~ ~ LiCo – The Linux Counter Project – Server Monitor ~ ~ ~

    …and here’s the CPU info line:

    CPU: {cpus[0]}% {cpus[1]}%

    • Alexander Löhner (Linux Counter)

      The usage= line is still missing a $ between ${usage} and {cpus…

      • zenjive

        I found a few others. The output is coming out ok now.
        I still get a few of the “(standard_in) 1: syntax error” and “(standard_in) 2: syntax error” errors at the start. The screen looks perfect now, so I’m not sure where those are coming from. I’ll scan over it again for typos. I guess something randomly stripped out the “$” tags.


  3. pcav

    Hi Alexander,
    thanks for this, interesting. Why not adding the code to a versioning system (gitlab, etc.)?
    All the best.

    • Alexander Löhner (Linux Counter)

      Hey pcav, thanks for that idea… well, this little script wouldn’t get a further development, I guess.
      But maybe I should make a little repository for all of the Bash Collection scripts. I’ll think about this.

    • Alexander Löhner (Linux Counter)

      Again thanks for that idea… I’ve just created such a repository for these bash collection scripts here:

      I’ve also modified all blog posts to link to this repository.

      • pcav

        Thanks for the quick reaction.

  4. Dan Mossor

    NUM_OF_CPU_CORES can be determined using nproc. I forked your repo and patched it here: https://github.com/danofsatx/lico-bash-collection/commit/f640cdefd86af1ed348b7529d680e4d12eb0b37f

    • Alexander Löhner (Linux Counter)

      Cool, thanks… can you please send me a pull request in the github repo? Thanks.

  5. Prasinos

    You could use “glances” instead ( https://nicolargo.github.io/glances/ ).
    Prettier, more robust, and actively maintained.

Leave a Reply