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.
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
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.
Great script, but it shows only one external IP. I have ipv4 and ipv6. I see only ipv6.
@Sven,
To include checking IPv6 address alongside IPv4, you can modify the script as follows:
Thank you so much, tecmint group. The script is great and working…
Good day, sir, I have copied the GitHub link to download the script, but I received an error message, the page was not found.
Hi, can you help me? your script
tecmint_monitoring.sh
not working to get datadf -h
because my server on AWS cloud.How to get data
df -h
to show inyour scripttecmint_montoring.sh
if i’ve filesystem like this:thanks
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
OK, thank you very much.
that’s works for me, and now I will send the results using email. I have used this instruction
but there is still an error like this:
can you help me again?
thanks
How to remove this script from server
@Anoop,
Just remove the downloaded script…
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,
Include this also in GitHub link.
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
How i can put it to run continuously?
@Rumesh,
Use a cron scheduler command to run it every hour or every day.
Followed your instructions to install on RHEL 5.8, and then ran “monitor”, with the results below:
Sample Output
It would be nice to know what it was supposed to do. I’m sure it wasn’t what happened.
@John,
You are using very old distribution, just update the
hostname
andfree
command options supported by your distro in the script.How to send its output as an email?
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
Put below content into script
Now run your script
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
@Baljit,
Yes, you have to install this Linux monitoring script on all Linux servers to monitor.
How to get its output in mail?
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.
the information loads up really slow on my server
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
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.
how can we find on squid that which internal ip is sending request to any-site by using Tls1.0
Very good job
Hey Tecmint,
Thanks for the awesome script! Made my job more easier. And appreciating the author for taking initiative in writing this simple script.
Authentication failure and I put my pass correctly???!!
“Edward” just use “-m” by changing free -h to free -m
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?
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?
Hi, I want this script output in mail, how to do please suggest me.
That love is only the logical answer to your work. Thanks.
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
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))
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
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
nice script
but how can i make it live and dynamic!
@Arash,
What you mean live? just simple download and execute the script to know the Server performance statistics..
Give inxi a try: https://github.com/smxi/inxi
It’s already in most distributions, including Ubuntu, just a simple apt-get.
inxi shows most everything you have here and has over 10 years development.
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?
@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..
@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.
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
@Immanuel,
Thanks for making the script compatible for Ubuntu and its derivatives, hope it will help all Ubuntu users…
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.
@Ex_rat,
Thanks for the changes and sharing the same with us, hope it will help other Linux users..
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?
@Andres,
Thanks for making the script compatible for all Linux distributions, but make sure you should give credit to Tecmint.
@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.
@Andres,
Thanks for keeping the Credit and yes our blessings always with you friend, yes you can push the script to the Github project and let me know once you done..
Let me know that too, thank you
Hi @Ravi,
The script is uploaded to GITHUB, https://github.com/atarallo/TECMINT_MONITOR/ . I’m adding changes in the Development branch. A few changes were contributed by a college and a third party.
@Andres,
Thanks for uploading the script on GitHub and also thanks for keeping its development…
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
@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..
Hi !!!!
I’ve been working on fixing that Issues on SuSE. I have them working on the script uploaded to github: https://github.com/atarallo/TECMINT_MONITOR/
The fixes that are specific to SuSE/OpenSuSE are in the Development branch. Please take the script from there, you’re also welcome to contribute code and suggestions.
@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..
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! :)
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.
I’ve added a check for availiability of CURL, you can find the script on:https://github.com/atarallo/TECMINT_MONITOR/ .Please download the development branch, all bugfixes and contributions are there.
@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..
Can you please share it on Github so we can fork it and optimize it
@Alji,
Sure, we will share this script on Github…
can you please let me know by comment when it is available on github ? thank you
@Alji,
Hopefully by this weekend will upload this script on github, will let you know..
the weekend is here :D
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
Hi, is the script available on Github please ?
@Alji,
The script is not available on Github, but we will upload it soon..
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”
@Ram,
Thanks for making this script compatible to Ubuntu distribution and also thanks for sharing with us.
in Debian8 3.16.0-4-amd64,
for load average, I usage {print $11 $12 $13}
#! /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
@Razz,
Thanks for sharing script with us, let me work on this and get back to you with solution..
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.
@Jeff,
Yes, we already aware about sysstat utility and to be fact we’ve already covered a detailed guide on the same, take a look at https://www.tecmint.com/install-sysstat-in-linux/.
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.
@Choudhry,
To delete tons of files, use the following find command with -delete option as shown:
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.
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)
@Eric,
That’s really a good findings, we really never thought of this, we will modify the script to work on all Red Hat and CentOS distributions..
Something applies to SuSE/OpenSuSE
./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
@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…
It is because #!/bin/bash should be at the 1st line of the script. It fixes this issue.
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.
i change it to free -m
I found an error with CentOS, but on Ubuntu it works fine. Great job!
@Filipe,
Could you please share the error that you’ve found in CentOS? and also mention the release version like CentOS 6 or 7..
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!
@Rick,
As requested, the script as been mailed to your email address. thanks..
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 ?
On Xubuntu 14.04.3, I found “/usr/bin/monitor: line 79: curl: command not found”.. whats wrong?
@Omah,
That means, you need to install curl package using apt-get command as shown, in order to function script properly..
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.
Working with ‘hostname -i’ instead of ‘hostname -I’ on arch.
@Dansanp,
Thanks for sharing the tip, hope it will help other arch users..:)
one line install
wget https://tecmint.com/wp-content/scripts/tecmint_monitor.sh && chmod +x tecmint_monitor.sh && tecmint_monitor -i
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
@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..
Very nice !!
Thanks for sharing !!
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.
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
@Satish,
Thanks for the kind words, here is the script that you need to download via wget and run as shown:
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.
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
@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.
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
@Rosey,
Thanks for the tip, about curl I think it comes pre-installed on most of the Linux distributions, still it’s worth mentioning….:)
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
Would be nice if you put this script under github then it’s more easy to track, fork and merge
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
@code7,
I just tried on my Ubuntu 15.04 and the script is working fine without any errors. Here is the screenshot of script of my Ubuntu 15.04 box.
https://www.tecmint.com/wp-content/uploads/2015/01/Linux-monitor-script.png
@code7
I’ve run into the same issue on minibian with zsh.
After switching to bash it’s running well.
@Ravi
Perhaps you can consider to move the shebang line to the very top of the script ?
@Douglas,
Sure I will move the shebang line to the top of the script as suggested..:)
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
@Jonus,
The following article will help you to produce script HTML pages using Apache..
https://www.tecmint.com/using-shell-script-to-automate-linux-system-maintenance-tasks/
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,
@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…
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.
Thanks @Makarand Maha,
I will surely add this to the next release. Till then you can use ‘watch’ command to collect output ar regular interval and write it to a file. I have written a post on watch command, which you may refer to generate output of a command/script at regular interval: https://www.tecmint.com/text-to-speech-in-terminal-schedule-a-job-and-watch-commands-in-linux/
(See Point Number 4).
This should fix your issue. If not let me know and I will do it for you.
How to remove this script from the installed, if i am no more using it
Chetan,
To remove this installed script from your system, run the below command as root, exactly as it is.
# rm /usr/bin/monitor
How do i unistall it if i don’t want to use it
Cheta,
To remove this installed script from your system, run the below command as root, exactly as it is.
# rm /usr/bin/monitor
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
where can i get the source code?
Please download the script as suggested using wget command, in the guide above.
The downloaded file contains all the source code, you need.
Thanks
Welcome @ sivaraman,
Keep Connected!
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.
Dear Ahmed Shibani,
Agree with you. Also it has been recommended by a lots of users.
Thanks for your feedback.
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
ohh thankyou! sleep_walker
I would recommend scan for nameserver this way:
cat /etc/resolv.conf |awk ‘/^nameserver/{print $2}’
Taken into account @dominix
Other than swap and ram this worked really well on CentOS release 6.6 (Final). Thank you.
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.
http://askubuntu.com/questions/282350/bash-install-sh-permission-denied-installing-intel-fortran-2011 this article just helped me
Nice link Hardik,
We have already shown how to run and install script in the article.
im running ubunt and loged in as root ,was able to download but says permission denied when installing , any help please!
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!
Really nice @ Debian Jessie
Thank you!
Welcome @Savvas, Keep Connected!
Very good script, thanks!
Any chance to have a parameter to avoid screen clear?
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?
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
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.
Why not use Conky?
Because you may not have GUI (Headed) Server specially in Enterprise and Production.
P.S : Conky runs in GUI
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
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
its not working with FreeBSD
@ 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
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.
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.
well make curl to install automatically too.
@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!
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
Thanks for the nice Link. We would like to know if there is any affiliating program you have for us?
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.
@ 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!
Which app you use for creating gifs?
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.
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
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!
why not use conky
http://conky.sourceforge.net/
Because you may not be running a GUI server always specially in enterprise and production.
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 ;) )
$ sudo apt-get install curl
and then run script. it should run without any error.
Thanks for this post ….. If Want to remove it… what is process to do..
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.
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!
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.
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 :)
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.
Welcome dype.
thanks for your feedback!
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.
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
Is this working for UNIX platform (Eg : Solaris) ?
Why don’t you check and let us know so that i can fix if any issue.
use monit https://mmonit.com/wiki/Monit/HowTo
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
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?
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.
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!