A Shell Script to Monitor Network, Disk Usage, Uptime, Load Average and RAM Usage in Linux

The duty of System Administrator is really tough as he/she has to monitor the servers, users, logs, create backup and blah blah blah. For the most repetitive task most of the administrator write a script to automate their day-to-day repetitive task. Here we have written a shell Script that do not aims to automate the task of a typical system admin, but it may be helpful at places and specially for those newbies who can get most of the information they require about their System, Network, Users, Load, Ram, host, Internal IP, External IP, Uptime, etc.

We have taken care of formatting the output (to certain extent). The Script don’t contains any Malicious contents and it can be run using Normal user Account. In-fact it is recommended to run this script as user and not as root.

Linux Server Health Monitoring
Shell Script to Monitor Linux System Health

You are free to use/modify/redistribute the below piece of code by giving proper credit to Tecmint and Author. We have tried to customize the output to the extent that nothing other than the required output is generated. We have tried to use those variables which are generally not used by Linux System and are probably free.

Minimum System Requirement

All you need to have is a working Linux box.

Dependency

There is no dependency required to use this package for a standard Linux Distribution. Moreover the script don’t requires root permission for execution purpose. However if you want to Install it, you need to enter root password once.

Security

We have taken care to ensure security of the system. Nothing additional package is required/installed. No root access required to run. Moreover code has been released under Apache 2.0 License, that means you are free to edit, modify and re-distribute by keeping Tecmint copyright.

How Do I Install and Run Script?

First, use following wget command to download the monitor script "tecmint_monitor.sh" and make it executable by setting appropriate permissions.

# wget https://tecmint.com/wp-content/scripts/tecmint_monitor.sh
# chmod 755 tecmint_monitor.sh

It is strongly advised to install the script as user and not as root. It will ask for root password and will install the necessary components at required places.

To install "tecmint_monitor.sh" script, simple use -i (install) option as shown below.

./tecmint_monitor.sh -i 

Enter root password when prompted. If everything goes well you will get a success message like shown below.

Password: 
Congratulations! Script Installed, now run monitor Command

After installation, you can run the script by calling command 'monitor' from any location or user. If you don’t like to install it, you need to include the location every-time you want to run it.

# ./Path/to/script/tecmint_monitor.sh

Now run monitor command from anywhere using any user account simply as:

$ monitor

TecMint Monitor Script in Action

As soon as you run the command you get various System related information which are:

  1. Internet Connectivity
  2. OS Type
  3. OS Name
  4. OS Version
  5. Architecture
  6. Kernel Release
  7. Hostname
  8. Internal IP
  9. External IP
  10. Name Servers
  11. Logged In users
  12. Ram Usages
  13. Swap Usages
  14. Disk Usages
  15. Load Average
  16. System Uptime

Check the installed version of script using -v (version) switch.

$ monitor -v

tecmint_monitor version 0.1
Designed by Tecmint.com
Released Under Apache 2.0 License

Conclusion

This script is working out of the box on a few machines I have checked. It should work the same for you as well. If you find any bug let us know in the comments. This is not the end. This is the beginning. You can take it to any level from here.

We’ve received few complaints that the script is not working on the few Linux distributions, and one of our regular reader Mr. Andres Tarallo, has taken the initiative and made the script compatible with all Linux distributions, you can find the updated script on GitHub at https://github.com/atarallo/TECMINT_MONITOR/.

If you feel like editing the script and carry it further you are free to do so giving us proper credit and also share the updated script with us so that we can update this article by giving you proper credit.

Don’t forget to share your thoughts or your script with us. We will be here to help you. Thank you for all the love you have given us. Keep Connected! Stay tuned.

If you liked this article, then do subscribe to email alerts for Linux tutorials. If you have any questions or doubts? do ask for help in the comments section.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

184 thoughts on “A Shell Script to Monitor Network, Disk Usage, Uptime, Load Average and RAM Usage in Linux”

  1. I was having some issues while running on centos so i made some edits.

    #! /bin/bash
    # unset any variable which system may be using

    # clear the screen
    clear

    unset tecreset os architecture kernelrelease internalip externalip nameserver loadaverage

    while getopts iv name
    do
    case $name in
    i)iopt=1;;
    v)vopt=1;;
    *)echo "Invalid arg";;
    esac
    done

    if [[ ! -z $iopt ]]
    then
    {
    wd=$(pwd)
    basename "$(test -L "$0" && readlink "$0" || echo "$0")" > /tmp/scriptname
    scriptname=$(echo -e -n $wd/ && cat /tmp/scriptname)
    su -c "cp $scriptname /usr/bin/monitor" root && echo "Congratulations! Script Installed, now run monitor Command" || echo "Installation failed"
    }
    fi

    if [[ ! -z $vopt ]]
    then
    {
    echo -e "tecmint_monitor version 0.1\nDesigned by Tecmint.com\nReleased Under Apache 2.0 License"
    }
    fi

    if [[ $# -eq 0 ]]
    then
    {

    # Define Variable tecreset
    tecreset=$(tput sgr0)

    # Check if connected to Internet or not
    ping -c 1 google.com &> /dev/null && echo -e '\E[32m'"Internet: $tecreset Connected" || echo -e '\E[32m'"Internet: $tecreset Disconnected"

    # Check OS Type
    os=$(uname -o)
    echo -e '\E[32m'"Operating System Type :" $tecreset $os

    # Check OS Release Version and Name
    cat /etc/issue |head -n 1 > /tmp/osrelease
    osname=$(cat /tmp/osrelease |awk '{print $1}')
    osrelease=$(cat /tmp/osrelease |awk '{print $3}')
    #cat /etc/os-release | grep 'NAME\|VERSION' | grep -v 'VERSION_ID' | grep -v 'PRETTY_NAME' > /tmp/osrelease
    echo -n -e '\E[32m'"OS Name :" $tecreset ; echo $osname \"
    echo -n -e '\E[32m'"OS Version :" $tecreset ; echo $osrelease \"

    # Check Architecture
    architecture=$(uname -m)
    echo -e '\E[32m'"Architecture :" $tecreset $architecture

    # Check Kernel Release
    kernelrelease=$(uname -r)
    echo -e '\E[32m'"Kernel Release :" $tecreset $kernelrelease

    # Check hostname
    echo -e '\E[32m'"Hostname :" $tecreset $HOSTNAME

    # Check Internal IP
    internalip=$(hostname -i)
    echo -e '\E[32m'"Internal IP :" $tecreset $internalip

    # Check External IP
    externalip=$(curl -s ipecho.net/plain;echo)
    echo -e '\E[32m'"External IP : $tecreset "$externalip

    # Check DNS
    nameservers=$(cat /etc/resolv.conf | sed '1 d' | awk '{print $2}')
    echo -e '\E[32m'"Name Servers :" $tecreset $nameservers

    # Check Logged In Users
    who>/tmp/who
    echo -e '\E[32m'"Logged In users :" $tecreset && cat /tmp/who

    # Check RAM and SWAP Usages
    free -m | grep -v "+\|You" > /tmp/ramcache
    echo -e '\E[32m'"Ram Usages :" $tecreset
    cat /tmp/ramcache | grep -v "Swap"
    echo -e '\E[32m'"Swap Usages :" $tecreset
    cat /tmp/ramcache | grep -v "Mem"

    # Check Disk Usages
    df -h| grep 'Filesystem\|da*' |grep -v tmpfs> /tmp/diskusage
    echo -e '\E[32m'"Disk Usages :" $tecreset
    cat /tmp/diskusage

    # Check Load Average
    loadaverage=$(top -n 1 -b | grep "load average:" | awk '{print $10 $11 $12}')
    echo -e '\E[32m'"Load Average :" $tecreset $loadaverage

    # Check System Uptime
    tecuptime=$(uptime | awk '{print $3,$4}' | cut -f1 -d,)
    echo -e '\E[32m'"System Uptime Days/(HH:MM) :" $tecreset $tecuptime

    # Unset Variables
    unset tecreset os architecture kernelrelease internalip externalip nameserver loadaverage

    # Remove Temporary Files
    rm /tmp/osrelease /tmp/who /tmp/ramcache /tmp/diskusage
    }
    fi
    shift $(($OPTIND -1))

    Reply
  2. elif [ -f /etc/gentoo-release ] ; then
    DIST=’Gentoo’
    PSUEDONAME=`cat /etc/gentoo-release | sed s/.*\(// | sed s/\)//`
    REV=`cat /etc/gentoo-release | sed s/.*release\ // | sed s/\ .*//`

    # Check Internal IP
    internalip=$(hostname -i)
    echo -e ‘\E[32m'”Internal IP :” $tecreset $internalip

    Reply
  3. Hi, very good script
    in>>
    /etc/osrelease
    i change>>
    /etc/*release

    2)
    # Check RAM and SWAP Usages
    free -h | grep -v + > /tmp/ramcache
    i change >>
    free -m | grep -v + > /tmp/ramcache
    3)
    df -h| grep ‘Filesystem\|/dev/sda*’ > /tmp/diskusage
    i change>>
    df -h| grep ‘Filesystem\|/dev/*’ > /tmp/diskusage

    Reply
  4. Hi. I’m looking at the script and see ‘\E[32m’ before almost every echo string. Should it actually be there? What about support for other os types?

    Reply
    • @Ariel,

      The updated version of script is available at Github, the link can be found at the bottom of the article, and about compatibility, yes it works on almost all flavors of Linux distributions..

      Reply
    • @Ariel, those are scape codes that make certain messages appear in color. Making the script work on other UNIXES (*BSD, AIX or Solaris) is not my priority. When I have time I’ll be testing it on AIX, that I have availiable.

      Reply
  5. Just tested the script. I made the following changes to get in working on Ubuntu and derivatives.

    removed the use of su.

    sudo cp $scriptname /usr/bin/monitor && echo “Congratulations! Script Installed, now run monitor Command” || echo “Installation failed”

    Added virtual hard disk and multiple hard disk.

    df -h| grep ‘Filesystem\|/dev/[s|v]d[a-z]*’ > /tmp/diskusage

    Reply
    • @Immanuel,

      Thanks for making the script compatible for Ubuntu and its derivatives, hope it will help all Ubuntu users…

      Reply
  6. Hi, i like your script ! :)

    # Check Disk Usages
    df -h| grep ‘Filesystem\|/dev/sda*’ > /tmp/diskusage

    #result:
    Disk Usages :
    /dev/sda2 439G 71M 417G 1% /home

    i change >>

    df -h| grep ‘Filesystem\|/dev’| sed ‘/tmpfs/d’ > /tmp/diskusage

    #result:
    Disk Usages :
    /dev/root 20G 661M 18G 4% /
    /dev/sda2 439G 71M 417G 1% /home

    Bye Ex.

    Reply
  7. Hi,

    I’ve discovered your script a month ago, thanks a former colleague. I’ve executed it on SuSE Enterprise (SLES), with some failures. I’m debugging it and making capable of running on other Linux other than Ubuntu.

    I want to upload the original script to GITHUB, to upload there my contributions. May I count with your blessing to do so?

    Reply
    • @Andres,

      Thanks for making the script compatible for all Linux distributions, but make sure you should give credit to Tecmint.

      Reply
      • @Ravi,
        I’ll credit Tecmint. It’s not my intention to delete the header or remove references to Tecmint.

        As said before it would be nice to have your blessing to upload the original Script to GITHUB, then I’ll be uploading there my changes.

        Feel free to write me a private message, the original script is great.

        Reply
      • HI Ravi,

        I’m also using SuSE Enterprise 11 Sp3 & getting many incorrect out-put.Here I’m attaching it:

        OS Name : OS Version : Architecture : x86_64
        Kernel Release : 3.0.76-0.11-default
        Hostname : DC1SAPCSSRT
        hostname: invalid option — ‘I’
        Usage: hostname [-v] {hostname|-F file} set hostname (from file)
        domainname [-v] {nisdomain|-F file} set NIS domainname (from file)
        hostname [-v] [-d|-f|-s|-a|-i|-y|-n] display formatted name
        hostname [-v] display hostname

        hostname -V|–version|-h|–help print info and exit

        dnsdomainname=hostname -d, {yp,nis,}domainname=hostname -y

        -s, –short short host name
        -a, –alias alias names
        -i, –ip-address addresses for the hostname
        -f, –fqdn, –long long host name (FQDN)
        -d, –domain DNS domain name
        -y, –yp, –nis NIS/YP domainname
        -F, –file read hostname or NIS domainname from given file

        This command can read or set the hostname or the NIS domainname. You can
        also read the DNS domain or the FQDN (fully qualified domain name).
        Unless you are using bind or NIS for host lookups you can change the
        FQDN (Fully Qualified Domain Name) and the DNS domain name (which is
        part of the FQDN) in the /etc/hosts file.
        Internal IP :
        External IP :
        Name Servers : Before static /etc/sysconfig/network/config NETCONFIG_DNS_STATIC_SEARCHLIST NETCONFIG_DNS_STATIC_SERVERS NETCONFIG_DNS_FORWARDER or NETCONFIG_DNS_POLICY=” See Note: may only, file Please intelenetglobal.com 10.200.132.15 10.200.132.16
        Logged In users :
        tushar pts/0 Jul 22 10:35 (10.10.11.229)
        free: invalid option — ‘h’
        usage: free [-b|-k|-m|-g] [-l] [-o] [-t] [-s delay] [-c count] [-V]
        -b,-k,-m,-g show output in bytes, KB, MB, or GB
        -l show detailed low and high memory statistics
        -o use old format (no -/+buffers/cache line)
        -t display total for RAM + swap
        -s update every [delay] seconds
        -c update [count] times
        -V display version information and exit
        Ram Usages :
        Swap Usages :
        Disk Usages :
        Filesystem Size Used Avail Use% Mounted on
        /dev/sda1 18G 12G 5.1G 70% /
        /dev/sda3 9.9G 1.2G 8.3G 12% /tmp
        /dev/sda5 9.9G 2.5G 6.9G 27% /usr/sap/SRT
        /dev/sda6 5.0G 970M 3.8G 21% /sapmnt/SRT
        /dev/sda7 2.0G 172M 1.7G 9% /usr/sap/hostctrl
        /dev/sda8 9.9G 1.4G 8.0G 15% /usr/sap/trans
        /dev/sda10 1.4T 1.2T 140G 90% /oracle
        /dev/sda9 20G 5.1G 14G 27% /oracle/SRT/112_64
        Load Average : loadaverage:0.24,
        System Uptime Days/(HH:MM) : 21 days

        Reply
        • @Tushar,

          You just need to change the options available on your Linux distribution in the script to make it compatible with your Linux OS, because every Linux flavor has different options, so just use accordingly..

          Reply
          • @Andres,

            Thanks for putting your efforts in making the script compatible with SuSE distribution, I haven’t yet checked the script on SuSE, but will certainly give a try today and see how it works..

          • @Andres,

            I’ve included the Github link to script in the article, so that users can download and keep further development of script under Tecmint license..

  8. At first my public ip address wasn’t displaying so i changed ipecho.net to myipaddress.com via vim but still didn’t work, found out i didn’t install curl yet because i did a “curl -s ipecho.net” or was it “curl -s myipaddress.com” and it didn’t recognize curl, since i changed tecmint.sh and forgot the exact syntax in the “curl -s ipecho.net” line, i just re-downloaded it and re-executed it and it finally worked! was happy to see all values, i had fun hahaha thanks and keep the educational contents coming! :)

    Reply
    • CURL is not mandatory to any distro I’m aware off. It’s very popular so many people think that it’s installed by default.

      I’ll add to the modified script (I’m working actually) to check for CURL availability.

      Reply
      • @Andres,

        Thanks a ton for uploading the script to Github and also making the script available for development, will download and test it, if its works perfectly on all Linux distributions, will replace the current script with this new one..

        Reply

Got something to say? Join the discussion.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.