Several simple system monitoring scripts in linux

Source: Internet
Author: User
In linux, some simple system monitoring script companies do not have a dedicated system administrator. Therefore, some server security measures have to be done by our programmers themselves. We do not know much about Linux servers and have checked some information, below are a few simple server monitoring scripts written by myself. we hope that the pipeline that passes by will refer... some simple system monitoring script companies in linux do not have dedicated system administrators. Therefore, some server security measures must be implemented by our programmers themselves. We do not know much about Linux servers, I checked some information. Below are some simple server monitoring scripts I have written. I hope that the pipeline that passes by can be pointed out and further corrected and improved! 1. log on to user monitoring on the server and send an email notification when you log on to more than two users. you can use the 139 email to receive the notification, facilitating text message notification. Bash Code :#! /Bin/bash IP = 'ifconfig eth0 | grep "inet addr" | awk '{print $2}' | cut-f 2-d ": "'Users = 'uptime | awk' {print $6}'' # if [$ users-ge 2] if [$ users-ge 2] then echo "$ IP server login users is more than 2 "| mail-s" warning: "***** @ 139.com fi 2. monitor the running status of MySQL. restart the service if it is not running normally. if the restart fails, send an email notification Bash code :#! /Bin/bash # The MySQL running string is determined based on the status information displayed when the database version is running normally./sbin/service mysql status | grep "MySQL running">/dev/null if [$? -Eq 0] then # check whether Port 3306 listens to netstat-ntp | grep 3306>/dev/null if [$? -Ne 0] then/sbin/service mysql restart sleep 3/sbin/service mysql status | grep "MySQL running">/dev/null if [$? -Ne 0] then echo "mysql service has stoped, Automatic startup failure, please start it manually! "| Mail-s" mysql is not running "*** @ 139.com fi else/sbin/service mysql start sleep 2; /sbin/service mysql status | grep "MySQL running">/dev/null if [$? -Ne 0] then echo "mysql service has stoped, Automatic startup failure, please start it manually! "| Mail-s" mysql is not running "*** @ 139.com fi 3. monitor disk space usage. when there is more than 80% partition space used, mail the Bash Code :#! /Bin/bash # set-x checkLog =/var/log/check-space.log fullFlag = 0 df-h> $ checkLog percent_list = $ (cat $ checkLog | awk '{print $5} '| grep-Eo "[0-9] + ") for num in $ percent_list do if [$ num-ge 80]; then fullFlag = 1 fi done if [$ fullFlag-eq 1]; then echo "$ (hostname ): used disk space is more than 80% "| mail-s" warning: disk space is not enough "*** @ 139.com fi ps: mail is sent by configuring mail to use an external SMTP server, use SMTP 163 Server. Edit/etc/mail. rc in vi and add the following code to the start part: exit and save wq! Set from = test@163.com set smtpsmtp = smtp.163.com set smtp-auth-user = test set smtp-auth-password = test123
Related Article

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.