A Shell Script to Monitor Network, Diske, Uptime, Load, and RAM in Linux

The duty of a System Administrator is really tough as they have to monitor the servers, users, logs, create backups, and so on. For the most repetitive tasks, many administrators write scripts to automate their day-to-day work.

Here, we have written a shell script that aims to help newbies by providing information about their system, network, users, load, RAM, host, internal IP, external IP, uptime, etc. While it may not automate all tasks of a typical system admin, it can be helpful in certain situations.

We have taken care of formatting the output to a certain extent. The script doesn’t contain any malicious content and it can be run using a normal user account. In fact, it is recommended to run this script as a user and not as root.

Linux Server Health Monitoring
Shell Script to Monitor Linux System Health

You are free to use, modify, or redistribute the piece of code below, provided that you give proper credit to Tecmint and the author. We have customized the output to ensure that only the required output is generated.

Additionally, we have utilized variables that are typically unused by the Linux system and are likely available.

Dependency

There is no dependency required to use this shell script on 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.

How Do I Install and Run Shell 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.

monitor

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:

  • Internet Connectivity
  • OS Type
  • OS Name
  • OS Version
  • Architecture
  • Kernel Release
  • Hostname
  • Internal IP
  • External IP
  • Name Servers
  • Logged In users
  • Ram Usages
  • Swap Usages
  • Disk Usages
  • Load Average
  • 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 bugs, let us know in the comments. This is not the end; it’s just the beginning. You can take it to any level from here.

We’ve received a few complaints that the script is not working on some Linux distributions. One of our regular readers, Mr. Andres Tarallo, has taken the initiative and made the script compatible with all Linux distributions. You can find the updated script on GitHub.

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

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

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Ravi Saive
I am an experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

189 Comments

Leave a Reply
    • @Sven,

      To include checking IPv6 address alongside IPv4, you can modify the script as follows:

      # Check Internal IPv4 and IPv6
      internalip=$(hostname -I)
      echo -e '\E[32m'"Internal IPv4 :" $tecreset $(echo $internalip | awk '{print $1}')
      echo -e '\E[32m'"Internal IPv6 :" $tecreset $(echo $internalip | awk '{print $2}')
      
      # Check External IPv4 and IPv6
      externalip=$(curl -s ifconfig.me)
      echo -e '\E[32m'"External IPv4 : $tecreset "$(echo $externalip | awk '{print $1}')
      echo -e '\E[32m'"External IPv6 : $tecreset "$(echo $externalip | awk '{print $2}')
      
      Reply
  1. Hi, can you help me? your script tecmint_monitoring.sh not working to get data df -h because my server on AWS cloud.

    How to get data df -h to show inyour script tecmint_montoring.sh if i’ve filesystem like this:

    Filesystem      Size  Used Avail Use% Mounted on
    udev            2.0G     0  2.0G   0% /dev
    tmpfs           395M  804K  394M   1% /run
    /dev/xvda1       30G   18G   12G  60% /
    tmpfs           2.0G     0  2.0G   0% /dev/shm
    tmpfs           5.0M     0  5.0M   0% /run/lock
    tmpfs           2.0G     0  2.0G   0% /sys/fs/cgroup
    /dev/loop0       29M   29M     0 100% /snap/amazon-ssm-agent/2012
    /dev/loop1       97M   97M     0 100% /snap/core/9436
    /dev/loop2       18M   18M     0 100% /snap/amazon-ssm-agent/1566
    /dev/loop3       98M   98M     0 100% /snap/core/9289
    tmpfs           395M     0  395M   0% /run/user/1000
    

    thanks

    Reply
    • Hi Bayu,

      Just remove “| grep ‘Filesystem\|/dev/sda*'” from “# Check Disk Usages” line.

      You will get all the mount points in the display. You have run the installation command again to reflect the changes.

      regards,
      Omkar

      Reply
      • OK, thank you very much.

        that’s works for me, and now I will send the results using email. I have used this instruction

        #! / bin / bash
        ./tecmint_monitor.sh 2> & 1> script.out
        mail -r [email protected] -s "Server monitoring result" [email protected] <script.out
        

        but there is still an error like this:

        ./tecmint_monitor.sh: 26: ./tecmint_monitor.sh: [[: not found
        ./tecmint_monitor.sh: 36: ./tecmint_monitor.sh: [[: not found
        ./tecmint_monitor.sh: 43: ./tecmint_monitor.sh: [[: not found
        

        can you help me again?

        thanks

        Reply
  2. For ‘OS Version’ : Linux Debian GNU/Linux 9 (stretch) 4.9.0-11-amd64(4.9.0-11-amd64 x86_64)
    ‘top -n 1 -b’ stdout:
    top – 22:27:53 up 13 min, 9 users, load average: 1.70, 2.23, 1.63
    So ‘tecmint_monitor.sh’ display:
    Load Average : average:2.02,2.35,

    Reply
  3. Include this also in GitHub link.

    # Last Reboot Time
    lastreboottime=$(who -b | awk '{print $3,$4}')
    echo -e '\E[32m'"Last Reboot Time :" $tecreset $lastreboottime
    
    Reply
  4. While running the given script in Ubuntu 18.04.3 LTS by using sh command, it throughout error like below.

    tecmint_monitor.sh: 23: tecmint_monitor.sh: [[: not found
    tecmint_monitor.sh: 33: tecmint_monitor.sh: [[: not found
    tecmint_monitor.sh: 40: tecmint_monitor.sh: [[: not found

    Please check and do the needful

    Reply
  5. Followed your instructions to install on RHEL 5.8, and then ran “monitor”, with the results below:

    [root@civaky3 ~]# monitor
    
    Sample Output
    Internet:  Connected
    Operating System Type :  GNU/Linux
    cat: /etc/os-release: No such file or directory
    OS Name : OS Version : Architecture :  x86_64
    Kernel Release :  2.6.18-308.13.1.el5
    Hostname :  civaky3.truthtechnologies.com
    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 :  208.82.219.167
    Name Servers :  204.117.214.10 199.2.252.10
    Logged In users :
    jhosie   pts/2        2019-03-05 15:45 (65.123.231.210)
    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/sda3              97M   40M   52M  44% /boot
    Load Average :  loadaverage:0.18,
    System Uptime Days/(HH:MM) :  331 days
    

    It would be nice to know what it was supposed to do. I’m sure it wasn’t what happened.

    Reply
    • @John,

      You are using very old distribution, just update the hostname and free command options supported by your distro in the script.

      Reply
    • Redirect stdout to file and then use mail function to mail to your email

      for this wrap your script into another bash script and run that

      vim anotherscript.sh 
      

      Put below content into script

      #!/bin/bash
      ./Path/to/script/tecmint_monitor.sh 2>&1 > script.out
      
      mail -r [email protected] -s "Server monitoring result "  [email protected] < script.out
      

      Now run your script

      # sh anotherscript.sh
      
      Reply
  6. How to run this script against multiple servers?
    Do I need to install this script to all the servers then extract the data, Please advise

    Reply
  7. Hi Andres Tarallo,

    Good day!, as I am working on Migration work for 250+ servers, wanted to collect the server related info along with cluster details.

    I would need your help to how to identify the servers are configured in cluster (VCS, RedHat Cluster, SCS, VxVM).

    Please suggest.

    Reply
  8. What if I want to run this script against a list of 100 remote servers and put that all that data in a nice spreadsheet how do I get that accomplished

    Reply
    • You could run the script via ssh. It won’t be a difficult task to make it run. Putting data on a Spreadsheet will require more work, maybe programming in Python/PERL or your favourite language with a API for dealing with spreadsheets.

      Reply
  9. Hey Tecmint,

    Thanks for the awesome script! Made my job more easier. And appreciating the author for taking initiative in writing this simple script.

    Reply
  10. The Free -h is giving an error.
    I tried -l and -m but the monitor still outputs -h. As though it isnt reading the file. any ideas?

    Reply
  11. GetVersionFromFile()
    {
    VERSION=`cat $1 | tr “\n” ‘ ‘ | sed s/.*VERSION.*=\ // `
    }
    I put # front of them,The Script‘s result did not change.What is their role?

    Reply
  12. Hi can you help me with this shell script for system admin.

    Create system admin menu with options below. And design the shell script to trap all exit/escape/suspend signals, so the user cannot do anything outside the menu. (Like output never getout of terminal when pressing cntrl + c, Only Quot command should terminate output)

    As a second step, start creating menu options. For example:

    u) manage users

    n) manage network

    q) quit

    Reply
  13. 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
  14. 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
  15. 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
  16. 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
  17. 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
  18. 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
  19. 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..

  20. 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
  21. Running Fedora 23 workstation
    Network interface is not eth0 (enp3s0)
    My server is not 192.168.1.1 (192.168.1.10)

    ifconfig –
    enp3s0: flags=4163 mtu 1500
    inet 192.168.1.168 netmask 255.255.255.0 broadcast 192.168.1.255
    inet6 fe80::867b:ebff:fe3d:7c63 prefixlen 64 scopeid 0x20
    ether 84:7b:eb:3d:7c:63 txqueuelen 1000 (Ethernet)
    RX packets 118056 bytes 110385471 (105.2 MiB)
    RX errors 0 dropped 0 overruns 0 frame 0
    TX packets 72364 bytes 9256712 (8.8 MiB)
    TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

    lo: flags=73 mtu 65536
    inet 127.0.0.1 netmask 255.0.0.0
    inet6 ::1 prefixlen 128 scopeid 0x10
    loop txqueuelen 1 (Local Loopback)
    RX packets 21 bytes 1753 (1.7 KiB)
    RX errors 0 dropped 0 overruns 0 frame 0
    TX packets 21 bytes 1753 (1.7 KiB)
    TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

    virbr0: flags=4099 mtu 1500
    inet 192.168.124.1 netmask 255.255.255.0 broadcast 192.168.124.255
    ether 52:54:00:88:3b:b9 txqueuelen 1000 (Ethernet)
    RX packets 0 bytes 0 (0.0 B)
    RX errors 0 dropped 0 overruns 0 frame 0
    TX packets 0 bytes 0 (0.0 B)
    TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
    Note the spaces at the start of the lines – I used -d ‘ ‘ and -f14 for RX and TX

    /etc/os-release
    NAME=Fedora
    VERSION=”23 (Workstation Edition)”
    ID=fedora
    VERSION_ID=23
    PRETTY_NAME=”Fedora 23 (Workstation Edition)”
    ANSI_COLOR=”0;34″
    CPE_NAME=”cpe:/o:fedoraproject:fedora:23″
    HOME_URL=”https://fedoraproject.org/”
    BUG_REPORT_URL=”https://bugzilla.redhat.com/”
    REDHAT_BUGZILLA_PRODUCT=”Fedora”
    REDHAT_BUGZILLA_PRODUCT_VERSION=23
    REDHAT_SUPPORT_PRODUCT=”Fedora”
    REDHAT_SUPPORT_PRODUCT_VERSION=23
    PRIVACY_POLICY_URL=https://fedoraproject.org/wiki/Legal:PrivacyPolicy
    VARIANT=”Workstation Edition”
    VARIANT_ID=workstation
    Note PRETTY_NAME and CPE_NAME

    /etc/resolve.conf
    # Generated by NetworkManager
    search workstation.sub.uk
    nameserver 192.168.1.10
    I used:
    dns=$(cat /etc/resolv.conf | grep nameserver | awk ‘{print $2}’)

    It all seems to be working now
    Hope this helps
    David

    Reply
  22. hi I just edited the script for my ubuntu

    here it is

    #!/bin/bash
    #OS release
    echo “##########################”
    echo -e “\e[1;32mWELCOME TO SPIDY Ver 1.0.2\e[0m”
    echo “##########################”
    echo “”
    cuser=$(whoami)
    echo -e “\e[1;33mHello $cuser\e[0m”
    echo ” ”
    os=$(cat /etc/os-release | grep _NAME | cut -d= -f2)
    echo -e “\e[1;36mOS Release\e[0m: $os”
    #OS type
    type=$(uname -o)
    echo -e “\e[1;36mOS Type\e[0m: $type”
    #OS Version
    ver=$(cat /etc/os-release | grep -w “VERSION” |cut -d= -f2)
    echo -e “\e[1;36mOS Version\e[0m: $ver”
    #OS Architecture
    arc=$(uname -m)
    echo -e “\e[1;36mOS Architecture \e[0m: $arc”
    #Kernel Release
    knl=$(uname -r)
    echo -e “\e[1;36mKernel Release\e[0m: $knl”
    #Network
    ping -c 1 192.168.1.1 &> /dev/null && echo -e “\e[1;36mNetwork\e[0m:\e[1;32m UP\e[0m” || echo -e ” \e[1;36mNetwork\e[0m :\e[1;31m Down\e[0m”
    #Internet
    ping -c 1 google.com &> /dev/null && echo -e “\e[1;36mInternet\e[0m:\e[1;32m Connected\e[0m” || echo -e “\e[1;36mInternet\e[0m :\e[1;31m Diconnected\e[0m”
    #Network speed
    rx=$(ifconfig eth0 | grep bytes | grep RX | cut -d ‘:’ -f2 | cut -d ‘ ‘ -f 1)
    tx=$(ifconfig eth0 | grep bytes | grep TX | cut -d ‘:’ -f3 | cut -d ‘ ‘ -f 1)
    rxd=$(echo $(($rx / 1000000))” MB”;)
    txd=$(echo $(($tx / 1000000))” MB”;)
    echo -e “\e[1;36mRecived \e[0m: \e[1;31m $rxd\e[0m”
    echo -e “\e[1;36mSent \e[0m: \e[1;35m $txd\e[0m”
    #Hostname
    hn=$(hostname)
    echo -e “\e[1;36mHostname\e[0m: \e[1;33m$hn\e[0m”
    #Internal IP
    ip=$( ifconfig |grep Bcast |cut -d: -f2 |cut -dB -f1)
    echo -e “\e[1;36mInternal IP\e[0m: \e[1;32m$ip\e[0m”
    #External IP
    eip=$(dig +short myip.opendns.com @resolver1.opendns.com)
    echo -e “\e[1;36mExternal IP\e[0m: \e[1;35m$eip\e[0m”
    #DNS
    dns=$(cat /etc/resolv.conf | sed ‘1 d’ | awk ‘{print $2}’| sed -n 4p)
    echo -e “\e[1;36mDNS Server\e[0m : $dns”
    #Current logged users
    cuser=$(whoami)
    echo -e “\e[1;36mCurrent user\e[0m: $cuser”
    #Logged users
    user=$(who)
    echo -e “\e[1;36mLoged in users\e[0m ”
    echo “$user”
    #RAM use
    t=$(free -h | grep -v + |grep total)
    echo ” $t ”
    ram=$(free -h | grep -v + |grep Mem)
    echo -e “\e[1;36mRam usage\e[0m : \e[1;31m$ram\e[0m”
    #SWAP use
    swap=$(free -h | grep -v + |grep Swap)
    echo -e “\e[1;36mSwap usage\e[0m : \e[1;34m$swap\e[0m”
    #Disk usage
    disk=$(df -h| grep ‘Filesystem\|/dev/sda*’)
    echo -e “\e[1;36mYour disk usage\e[0m ”
    echo -e “\e[1;33m$disk\e[0m ”
    #Load avaerage
    load=$(cat /proc/loadavg |cut -d. -f1)
    echo -e “\e[1;36mCurrent CPU Load is\e[0m : $load ”
    #Uptime
    up=$(uptime | awk ‘{print $3,$4}’ | cut -f1 -d,)
    echo -e “\e[1;36mSystem Uptime\e[0m: \e[1;32m $up\e[0m”

    Reply
  23. #! /bin/bash
    [email protected]
    for i in $(cat ping.txt)
    do
    fping $i >/dev/null
    if [ $? -ne 0 ]
    then
    echo “$i is down”|mailx -s “connectivity test” $email
    fi
    done

    This script is working fine but the problem is it is sending the mail individually for each host ,suppose number of unreachable server is more ( in three digit ) .. i don’t think this is best practice to do this

    i want see list of down hosts in one email ,could you help me to modify the script .. i am new in shell scripting please help . Many Thanks

    Reply
  24. There is a utility named sysstat that is available on many Linux distributions. Sysstat collects a variety of metrics every few minutes. For RAM, CPU, Disk IO, Network, Swap, etc, systat is very useful. When having issues on servers, sometimes I script sysstat to email me data for key metrics, e.g. swap utilization.

    Reply
  25. very very help full , i want to remove a large no of folders from centos 6 server any script because rm -rf does not work.

    Reply
      • Be very careful when using dot notation combined with delete. The command itself can remove anything, even if you are located in a different directory than you might expect, especially when operating as the root user.

        Reply
  26. On Centos/RHEL the command to read /etc/os-release will not work, since these distros do not have those. Might need to have a search for *-release and check for centos or redhat, then parse differently from there, since those also do not put the info on separate lines..

    Example centos-release:
    [root@server bin]# cat /etc/centos-release
    CentOS release 6.7 (Final)

    Example redhat-release
    [root@cas ~]# cat /etc/redhat-release
    Red Hat Enterprise Linux Server release 6.7 (Santiago)

    Reply
  27. ./tecmint_monitor.sh: 26: ./tecmint_monitor.sh: [[: not found
    ./tecmint_monitor.sh: 36: ./tecmint_monitor.sh: [[: not found
    ./tecmint_monitor.sh: 43: ./tecmint_monitor.sh: [[: not found

    Reply
    • @Preslav,

      On which Linux distribution you’ve tried it? let me know so that we can work around your issue and come up with right solution…

      Reply
    • I got the same error, but it works if you launch it with ‘bash tecmint_monitor.sh’ , instead of ‘sh tecmint_monitor.sh’

      On the other hand, in Ubuntu 12.04.4 (i need to update, i know), there’s a problem with the command free.

      When I launch the script, I get ” free: invalid option — ‘h’ ” If I change the line “free -h” to “free” it works, by of course all in bytes.

      Reply
    • @Filipe,

      Could you please share the error that you’ve found in CentOS? and also mention the release version like CentOS 6 or 7..

      Reply
  28. Hey there. Any chance you can post a link to the script? I don’t have wget from this machine and the machine(s) I’d like to monitor are on a closed enclave. Thanks!

    Reply
  29. if we have a data center or upload center like dropbox how can we write an script to monitor all the servers at once and check which server has more load and using more bandwidth ?

    Reply
    • @Omah,

      That means, you need to install curl package using apt-get command as shown, in order to function script properly..

      $ sudo apt-get install curl
      
      Reply
  30. On arch doesn’t work properly, it uses GNU ‘hostname’ which has fewer options than de debian one, and instead the host IP’s you can read the following message:

    hostname: invalid option — ‘I’
    Try ‘hostname –help’ or ‘hostname –usage’ for more information.

    Reply
  31. One correction

    for load average command should be
    top -n 1 -b | grep “load average:”|awk ‘{print $12 $13 $14}’

    I verified it on Ubuntu 14.04
    Not sure about other distros

    Reply
    • @Utkarsh,

      Thanks for the tip, let me check the command on the all distributions, if works perfectly will modify the load average command as suggested..

      Reply
  32. Nice script! Apart from the internal script running, it’s always best to have an external monitoring script to monitor the server/VPS environment. Downtime sometimes may be originated from the network disconnection or instability from the data center which your host is hosted on which is not something detectable by scripts running on the server side. More over when the server is highly overload, script which should trigger any email alert may also be affected due to performance issue.

    Reply
  33. Hi Avishek,

    Good to see the article about the system usage.
    Sorry to ask you. I couldn’t find the script to download. Can you share the script.

    Thanks,
    Satish

    Reply
    • @Satish,
      Thanks for the kind words, here is the script that you need to download via wget and run as shown:

      # wget https://tecmint.com/wp-content/scripts/tecmint_monitor.sh
      # chmod 755 tecmint_monitor.sh
      
      Reply
  34. There is just small error I got. I am using redhat 6 server. free -h command is not working here.
    so Please correct the script “free h” in place if “free -h”.
    Apart from this Everything is fine.

    Thank you.

    Reply
  35. Dear sir,
    I Like your tutorials very much. It helps me a lot. Can you please share the tutorials about how to install perl & jboss in linux.

    Thanks & Regards,
    Reetesh
    GST

    Reply
    • @Reetesh,
      Thanks for the kind words, I think perl comes with pre-installed with all Linux distributions, if not you can install them using yum or apt package manager command as per you respective distributions, and about jboss, we’ve not covered yet, but we will cover a detailed series about Jboss in upcoming articles. Stay tuned to TecMint.

      Reply
  36. Love it! but, you said there were no dependences, but that is incorrect. Curl is need and is not installed by default in Debian 7/8. Just add the following line at the beginning just after the shebang! line.

    if [[ ! -f /usr/bin/curl ]]; then apt-get install curl -y; fi

    Really only need the apt-get install curl, But I like to check of existence first and install only if needed. And add sudo if you are not root

    Reply
    • @Rosey,
      Thanks for the tip, about curl I think it comes pre-installed on most of the Linux distributions, still it’s worth mentioning….:)

      Reply
      • In similar case we’ve used this construction:

        if [[ $(which wget 2>/dev/null) ]]; then # Try wget, automatic redirect
        … use wget …
        elif [[ $(which curl 2>/dev/null) ]]; then # Try curl, -L – for redirect
        … use curl …
        else
        Die “DOWNLOAD ERROR! No curl or wget available”
        fi

        Reply
  37. hey do know if im posting in the right form but i’m having a problem installing the monitor script on ubuntu 15.04 this is my result after try to install:/tecmint_monitor.sh: 26: ./tecmint_monitor.sh: [[: not found

    Reply
  38. Hi,

    Is there any one who help / can guide me the correct steps of use bash shell script as a CGI
    and show this script output on HTML page using Apache ?

    Thanks in Advance!

    -Jonus Joseph

    Reply
  39. The script is not providing proper output on all distros.

    Example: http://share.servergur.us/#vg5j2G9PDuy0izPDfV04hQ

    [~/scripts]# cat /etc/redhat-release
    CentOS release 6.6 (Final)
    [~/scripts]# free -V
    procps version 3.2.8

    free -h is not an allowed flag in this standard version of ‘free’ in CentOS 6.6

    Also, /etc/os-release is not available in CentOS, rather /etc/redhat-release.

    As well, not everyone will be using /dev/sda as their primary partition. Eg, in my raid solution, I’m using /dev/mapper/vg*

    Regards,

    Reply
    • @David,
      Yes you correct, some of the flags are different in other distributions, better just replace the one that supports your distro in the script and use it..this is what I can suggest you for now…

      Reply
  40. Hi Avishek,

    Thanks for such a useful script. For me it is quite a handy when boss asks us to check server load or disk space like values.
    But, it just runs for once and ends there.
    Is there any way that I can use it in loop, so the output will keep updating every 5 seconds or so. (Apologies for my bad english).

    Thanks,
    Makarand Maha.

    Reply
    • Chetan,
      To remove this installed script from your system, run the below command as root, exactly as it is.
      # rm /usr/bin/monitor

      Reply
    • Cheta,
      To remove this installed script from your system, run the below command as root, exactly as it is.
      # rm /usr/bin/monitor

      Reply
  41. memory usage should be this
    free | grep -v + > /tmp/ramcache
    and disk usage should be this
    df -h| egrep -i ‘Filesystem|/dev/.da*’ > /tmp/diskusage in centos system and ubuntu

    Reply
    • Please download the script as suggested using wget command, in the guide above.
      The downloaded file contains all the source code, you need.

      Reply
  42. Small fix, move the #! /bin/bash line to the top of the file. Otherwise the script won’t run properly if not using any other shell such as sh or zsh.

    Reply
    • Dear Ahmed Shibani,
      Agree with you. Also it has been recommended by a lots of users.
      Thanks for your feedback.

      Reply
  43. This script is ugly as hell.

    1] `cat file | grep regex’ instead of `grep regex file’
    2] cat | grep | grep | grep – and only to create temp file which will be processed after that again !!!
    3] running top instead of reading /proc/loadavg directly
    4] cat | sed | awk – why don’t you create one script either for sed or awk?
    5] why to store into tmpfile when not necessary?
    who > tmpfile
    echo && cat
    use instead
    echo && who

    Reply
    • Dear Kristal, In your case RAM and SWAP output was not clear as indicated by you. I have tested it on Debian and Mint. I agree that due to difference in implementation of same thing by different distros, differently, there could be an issue like this. Let me know what distribution you tested it upon, so that i can work to make it compatible.

      Reply
  44. im running ubunt and loged in as root ,was able to download but says permission denied when installing , any help please!

    Reply
    • All you need to do is read the article again!

      For quick tips
      1. Download the script
      2. chmod 755 Script_name.sh
      3. ./Script_name.sh
      Alternatively, to install
      4. ./Script_name.sh -i

      Welcome!

      Reply
    • Dear Luca,
      you want to avoid screen clearing at the beginning of the script?

      If yes you may just put a # in the beginning of script where the text matches ‘clear’, save and execute.
      Also let me know why you don’t want to clear the screen?

      Reply
      • I simply don’t like so much, that’s it ;) Thanks for the suggestions.
        I’m checking on CentOS 6.6 (virtualized on qemu) but
        – os type is not detected
        – there are issues with detection of ram, disk (I understand could be a mess with various partitions) and load average
        Internet: Connected
        Operating System Type : GNU/Linux
        cat: /etc/os-release: No such file or directory
        OS Name : OS Version : Architecture : x86_64
        Kernel Release : 2.6.32-504.12.2.el6.x86_64
        Hostname : qapv12
        Internal IP : xxxxxxxx
        External IP : xxxxxxxx
        Name Servers : xxxxxxxx
        Logged In users :
        luca pts/0 2015-05-22 13:29 (xxxxxxxxx)
        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
        -a show available memory if exported by kernel (>80 characters per line)
        -V display version information and exit
        Ram Usages :
        Swap Usages :
        Disk Usages :
        Filesystem Size Used Avail Use% Mounted on
        Load Average : loadaverage:0.13,
        System Uptime Days/(HH:MM) : 59 days

        Reply
        • Dear Luca,
          as said earlier such difference in output is because of difference in implementation of same thing by different Linux Distribution. Give me some time so that i can modify it for CentOS GNU/Linux, so that next time you can say “I Like this Very Much.” Keep Connected. Thanks.

          Reply
    • Because you may not have GUI (Headed) Server specially in Enterprise and Production.

      P.S : Conky runs in GUI

      Reply
  45. Hi,
    Didn’t worked properly in Centos:
    – no OS Name and Version
    – Outputs the erro in the free command (free: invalid option — ‘h’ …)
    – Als no Ram, Swap and Disk usages
    Regards

    Reply
    • Pedro,
      Due to non-uniform implementation of same command and switch differently by different distribution this is not working as it should be.

      The good thing is i am working on next release of this on git.
      Will soon fix those issues. Till then keep connected. Enjoy

      Reply
    • @ Aryan
      Due to non-uniform implementation of same command and switch differently by different distribution this is not working as it should be.

      The good thing is i am working on next release of this on git.
      Will soon fix those issues. Till then keep connected. Enjoy

      Reply
  46. I like this script and may use in my teaching. However I found two issues that already have been mentioned. With Mageia4 I also get errors with ‘hostname -I’ (woks fine with ‘hostname -i’) and ‘free -h’ (works better with ‘free -m’). Just o confirm that this is not just an issue with Ubuntu.

    Reply
    • smaxx we are happy to know that you find this script helpful. Moreover It is a proud to listen that our script will be used by a nation builder aka teacher to our future generation. Thanks for your’s tips. It is quite expected as all Linux System don’t follow same/Universal way of implementing commands and configuration.

      Reply
    • @Subhranil Dey, Thanks for your feedback. We are working on the next version of this script where we would improved user’s experiance and add a few things. Keep Connected!

      Reply
  47. Thanks, this is a very helpful script for SysAdmins.

    We are also trying to help the day-to-day of SysAdmins in the capacity of uptime and performance monitoring with a tool called Happy Apps: monitoring without the noise. Free accounts at http://www.happyapps.io

    Reply
  48. Hi, great script!
    – but ‘hostname -I’ doesn’t work in openSuse12.3, I think it should be a normal ‘i’, not a capital one…

    Best regards,
    Verner K.

    Reply
    • @ Verner Kjaersgaard,
      Agree its bcz of different implementation of same thing by different distributions. We will be fixing this in our next release. Keep Connected!

      Reply
    • Dear Gaurav,
      That is an small application written by us but as of now it has not been named. Neither has been decided to publish the application under what License.

      Any help/suggestion in script is welcome.

      Reply
  49. Doesn’t work properly under xen.

    # Check Disk Usages
    df -h| grep ‘Filesystem\|/dev/sda*’ > /tmp/diskusage
    echo -e ‘\E[32m'”Disk Usages :” $tecreset
    cat /tmp/diskusage

    Reply
    • Dear Shamrock,
      i don’t have a xen setup to test and fix the discrepancies, however if i could get a ssh access to a xen setup i would like to customize the script till it is fixed. Thanks for taking the time and providing us with your valuable feedback. Keep Connected!

      Reply
  50. Very nice script, thanks so much.Linux forever 100 % optimal O.S.
    i found a issue see:
    ./tecmint_monitor.sh: linha 79: curl: comando não encontrado curl: command not found
    I use peppermint 5 ( Ubuntu 14.04 based ) and great O.S.
    thanks and advance ( keep running ;) )

    Reply
    • If you have installed it you may like to remove it as

      # rm /usr/bin/monitor (as root)
      or
      $ sudo /usr/bin/monitor (on sudo based system)
      and all done!

      will add uninstall in the next version.

      Reply
  51. Word of advice: Pass your scripts through shellcheck.net and think about portability. This won’t run well on Solaris/HP-UX/etc

    And I’m not sure I see the value in assigning variables for single use, especially to use in echo, when you should be using printf. Finally, don’t encourage the habit of “cat /some/file | someprocessing”. This is a useless use of cat (UUOC) (yes, google that). cat is for conCATenating files together, not for dumping file contents into a pipe – except for a few rare edge cases. This kind of cat usage is a glaring indicator of a newbie coder.

    Example:
    cat /etc/os-release | grep ‘NAME\|VERSION’

    A better way to write this is:
    grep ‘NAME\|VERSION’ /etc/os-release

    I’ve rewritten the script in my own image, but I haven’t built much more into it, and I’ve intentionally left a couple of issues because my carefactor is low. See if you can spot them. Grab the code here:

    http://pastebin.com/wVsgiYeM

    Pass yours through shellcheck, then mine through shellcheck and compare. Learn why not to UUOC, why to use printf over echo, and how to quote variables properly.

    Good luck!

    Reply
    • Dear Someguy McPants

      I have not written it for HP-UX and solaris. Moreover this project was just the work of a couple of hours of mine and not something i was funded/paid. But this is not the excuse i would give and will ask for some time to make it run on HP-UX and Solaris. I agree to your point that defining variables for single action is not recommended moreover using printf in place of echo and use cat as least as possible is true. I did this only to play safer, making a temporary copy of command and then grep/awk/sed/cut into it. I tried what you are suggesting now, while writing the script but it was getting a little complex with filter.

      Don’t worry! i will be fixing it soon and add certain other system information to it as well as format it a little more.

      Thanks for your concern and feedback.

      Reply
    • Moreover the problem with your suggestion is
      grep ‘NAME\|VERSION’ /etc/os-release will require root access and i tried to make this script run without root as far as possible. that’s why i used ip and not ifconfig. Thanks for writing such a nice critics :)

      Reply
  52. Hi

    Thanks for the script.

    I replace “su -c “cp $scriptname /usr/bin/monitor” root”
    by : sudo cp $scriptname /usr/bin/monitor

    login as root is not allowed on the systems I manage.

    Reply
  53. This is throwing an error in Ubuntu 10.04: “free: invalid option — ‘h'”, so it doesn’t report Ram, Swap and Disk Usages, and Filesystem stats.

    Reply
    • David i have checked it on Debian, CentOS and Mint. it run well without any issue. give me some time and let me figure out why it is throwing such error on Ubuntu

      Reply
  54. I am working in hp bit confused abt sos report where to check the issue and failure components can you help me on creating script so tat all the information can get in one place

    Reply
    • Dear ramesh,
      though i have never worked on HP-UX and i am not aware of how it reports. Will you please share a complete log of sos report and what information you want from that, in very clear language?

      Reply
  55. thanks for the script, its helpful for live status checking, just i think that it need more flexibility on disk size monitoring because it looks just to / /dev/sda running it on an ubuntu machine where system is installed on a separated part. and on LVM mode it shows an empty result.

    Reply
    • Yeah! khaled Jamel

      I have used sda* in the code you may include one more grep code there to look after all lvm.
      It is not going to be any difficult.
      Keep connected!

      Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.