Simple scripts for monitoring Linux systems

Source: Internet
Author: User
Tags domain name server disk usage diskusage nameserver

  • I first paste the script here, convenient for everyone to watch, which is also borrowed from a lot of other big God things, this script is mainly used to monitor the server, users, logs, but also to create backups, and so on. Recently learned shell more, use this to practice practiced hand, relatively simple, we make a look at it.


  • #!/bin/bash10#unset any variable which system could be using11 12#Clear the screen13Clear14 15unset tecreset OS architecture kernelrelease internalip externalip nameserver loadaverage16 17 whilegetopts IV Name18 DoCase $nameinchi) iopt=1;; V) vopt=1;; *) echo"Invalid Arg";; 23Esac24 Done25 26if[[ ! -Z $iopt]] 27 Then28 { Wd=$ (PWD)BaseName"$ (test-l"$"&& Readlink"$"| | | echo"$")">/tmp/ScriptNamescriptname=$ (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"33 } 34fi35 36if[[ ! -Z $vopt]] 37 Then38 { Echo-e"tecmint_monitor version 0.1\ndesigned by tecmint.com\nreleased under Apache 2.0 License"40 } 41fi42 43if[[ $#-eq 0]]44 Then45 { 46 47 48#Define Variable Tecresettecreset=$ (tput sgr0)50 51#Check if connected to the Internet or notPing-c 1 google.com &>/dev/null && echo-e'\e[32m' "Internet: $tecreset Connected"|| Echo-e'\e[32m' "Internet: $tecreset disconnected"53 54#Check OS Typeos=$ (Uname-o)Echo-e'\e[32m' "Operating System Type:"$tecreset $os57 58#Check OS Release Version and NameCat/etc/os-release | Grep'name\| VERSION'| Grep-v'version_id'| Grep-v'Pretty_name'>/tmp/OsreleaseEcho-n-E'\e[32m' "OS Name:"$tecreset && Cat/tmp/osrelease | Grep-v"VERSION"| Cut-f2-d\"Echo-n-E'\e[32m' "OS Version:"$tecreset && Cat/tmp/osrelease | Grep-v"NAME"| Cut-f2-d\"62 63#Check Architecturearchitecture=$ (Uname-m)Echo-e'\e[32m' "Architecture:"$tecreset $architecture66 67#Check Kernel Releasekernelrelease=$ (Uname-R)Echo-e'\e[32m' "Kernel Release:"$tecreset $kernelrelease70 71#Check hostnameEcho-e'\e[32m' "Hostname:"$tecreset $HOSTNAME73 74#Check Internal IPinternalip=$ (Hostname-I)Echo-e'\e[32m' "Internal IP:"$tecreset $internalip77 78#Check External IPexternalip=$ (Curl-s ipecho.net/Plain;echo)Echo-e'\e[32m' "External IP: $tecreset"$externalip81 82#Check DNSnameservers=$ (cat/etc/resolv.conf | sed)'1 D'| Awk'{print $}') Echo-e'\e[32m' "Name Servers:"$tecreset $nameservers85 86#Check logged in Userswho>/tmp/W.H.O.Echo-e'\e[32m' "logged in users:"$tecreset && cat/tmp/W.H.O.89 90#Check RAM and SWAP Usagesfree-h | Grep-v + >/tmp/RamcacheEcho-e'\e[32m' "Ram Usages:"$tecresetCat/tmp/ramcache | Grep-v"Swap"94 ECHO-E'\e[32m' "Swap Usages:"$tecresetCat/tmp/ramcache | Grep-v"Mem"96 97#Check Disk Usages98 df-h| Grep'filesystem\|/dev/sda*'>/tmp/DiskusageEcho-e'\e[32m' "Disk Usages:"$tecresetcat/tmp/Diskusage101 102#Check Load Average103 loadaverage=$ (Top-n 1-b | grep"load Average:"| Awk'{print $ $11 $ $}')104 ECHO-E'\e[32m' "Load Average:"$tecreset $loadaverage105 106#Check System Uptime107 tecuptime=$ (Uptime | awk'{print $3,$4}'| CUT-F1-D,)108 ECHO-E'\e[32m' "System Uptime days/(hh:mm):"$tecreset $tecuptime109 110#Unset Variables111unset tecreset OS architecture kernelrelease internalip externalip nameserver loadaverage112 113#Remove Temporary Filesrm/tmp/osrelease/tmp/who/tmp/ramcache/tmp/Diskusage115 }116fi117 Shift $ (($OPTIND-1))

  • This script can be installed or run directly, to see your own preferences. Non-toxic harmless, you can try, hahaha.
    • installation command:./tecmint_monitor.sh -i
    • Execute script command:./tecmint_monitor.sh
    • You can then execute the Monitor command in any one place, which is as simple as this:
    • You run the command to get a variety of the following information about the system:
      • Internet connectivity
      • Operating system Type
      • Operating system name
      • Operating system version
      • Architecture
      • Kernel version
      • Host Name
      • Internal IP
      • External IP
      • Domain Name server
      • Logged in user
      • Memory utilization
      • Swap partition usage
      • Disk usage
      • Average load
      • System Boot Time

    • This is run:


  • This script is still relatively useful, the daily monitoring system of some of the work to let it dry, so I am more relaxed.

Simple scripts for monitoring Linux systems

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.