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