Shell monitoring scripts----hard disk space and memory

Source: Internet
Author: User

Real-time monitoring of the local memory and the remaining space on the hard disk, the remaining memory is less than 500M, the root partition remaining space is less than 1000M send alarm message to the root administrator

1 Writing scripts
[Email protected] ~]# vim jiankong.sh

#!/bin/bash
#此脚本中数字单位是kb, you can adjust the number size according to your needs
#此脚本整体定义函数放入后台执行
Jiankong () {
disksize=$ (DF/| awk '/\//{print$4} ')
memsize=$ (Free | awk '/mem/{print$4} ')
While:
Do
If [$disksize-le 1024000]; Then
Mail-s Warning Root <<eof
Warning: Hard disk space is not enough!!
Eof
Fi
If [$memsize-le 512000]; Then
Mail-s Warning Root <<eof
Warning: Insufficient memory space!!
Eof
Fi
Done
}
Jiankong &

[Email protected] ~]# chmod +x/root/jiankong.sh

2 Test Results
[Email protected] ~]#./jiankong.sh
[[Email protected] ~]# PS aux | grep jiankong//You can see that the script is running in the background
Root 20250 99.5 0.0 113116 804 pts/0 R 06:45 15:17/bin/bash./jiankong.sh

Shell monitoring scripts----hard disk space and memory

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.