shell监控脚本----硬盘空间和内存

实时监控本机内存和硬盘剩余空间,剩余内存小于 500M、根分区剩余空间小于 1000M 时发送报警邮件给root 管理员

1 写脚本
[[email protected] ~]# vim jiankong.sh

#!/bin/bash
#此脚本中数字单位是kb,可根据自己需要调整数字大小
#此脚本整体定义函数放入后台执行
jiankong () {
disksize=$(df /| awk ‘/\//{print$4}‘)
memsize=$(free | awk ‘/Mem/{print$4}‘)
while :
do
if [ $disksize -le 1024000 ]; then
mail -s Warning root <<EOF
警告:硬盘空间不足!!
EOF
fi
if [ $memsize -le 512000 ]; then
mail -s Warning root <<EOF
警告:内存空间不足!!
EOF
fi
done
}
jiankong &

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

2 测试结果
[[email protected] ~]# ./jiankong.sh
[[email protected] ~]# ps aux | grep jiankong //可以看到脚本正在后台运行
root 20250 99.5 0.0 113116 804 pts/0 R 06:45 15:17 /bin/bash ./jiankong.sh

原文地址:http://blog.51cto.com/13450962/2059979

时间: 2024-07-29 13:21:04

shell监控脚本----硬盘空间和内存的相关文章

利用shell监控cpu、磁盘、内存使用率

利用shell监控cpu.磁盘.内存使用率,达到警报阈值发邮件进行通知 并配合任务计划,即可及时获取报警信息 #!/bin/bash ############################################## #Author: Liuzhengwei - [email protected] #QQ:1135960569 #Last modified: 2017-04-19 21:50 #Filename: jiankong.sh #Description:  #########

shell监控脚本1

#!/bin/sh #count memory_used_rate,disk_used_rate  #@yuanwb 2015-5   #disk_used_rate #Depend on real storage place the parameter 'Location' need to alter. Location=/dev/sda1 Disk_Used_Rate1=$(df -h | grep $Location | awk '{print $5}') free1=`echo $Dis

shell监控脚本2

#!/bin/sh #count memory_used_rate,disk_used_rate  #@yuanwb 2015-5   #disk_used_rate #Depend on real storage place the parameter 'Location' need to alter. Location=/dev/sda1 Disk_Used_Rate1=$(df -h | grep $Location | awk '{print $5}') free1=`echo $Dis

shell监控脚本3

#!/bin/sh #count memory_used_rate,disk_used_rate  #@yuanwb 2015-5   #disk_used_rate #Depend on real storage place the parameter 'Location' need to alter. Location=/dev/sda1 Disk_Used_Rate1=$(df -h | grep $Location | awk '{print $5}') free1=`echo $Dis

shell监控脚本

shell脚本监控网站并实现邮件.短信报警 shell进程监控脚本(发送邮件报警) Shell脚本监控服务器在线状态和邮件报警的方法 如果是139邮箱还可免费手机短信通知.注:通过系统直接发送mail容易被拦截,可使用mail连接第三方smtp发送邮件.

shell监控脚本4

#!/bin/sh #count memory_used_rate,disk_used_rate  #@yuanwb 2015-5   #disk_used_rate #Depend on real storage place the parameter 'Location' need to alter. Location=/dev/sda1 Disk_Used_Rate1=$(df -h | grep $Location | awk '{print $5}') free1=`echo $Dis

利用shell监控cpu、磁盘、内存使用率,达到警报阈值发邮件进行通知

#!/bin/bash#获取cpu使用率cpuUsage=top -n 1 | awk -F '[ %]+' 'NR==3 {print $2}'#获取磁盘使用率data_name="/dev/vda1"diskUsage=df -h | grep $data_name | awk -F '[ %]+' '{print $5}'logFile=/tmp/jiankong.log#获取内存情况mem_total=free -m | awk -F '[ :]+' 'NR==2{print

shell监控脚本,不考虑多用户情况

#!/bin/bash CheckProcess() { if [ "$1" = "" ]; then return 1 fi PROCESS_NUM=`ps -ef | grep "$1" | grep -v "grep" | wc -l` if [ $PROCESS_NUM -eq 1 ]; then return 0 else return 1 fi } while [ 1 ] ; do #输入进程名 echo &quo

shell监控进程状态,自启动

shell 监控脚本,通过会while true 实现,没有使用crontab #!/bin/bash source /etc/profile appname=aurora-gateway-provider-1.3.1_build2.jar #[jps 显示的 进程名称] app_path=/opt/workspace/aurora-gateway/ #[app_script 的上层目录,和启动方式配合,如 aurora-gateway的启动方式是 sh sbin/app.sh start] a