如何每分钟检测一次/(根)的使用率,如果超过80% 就给/var/log/messgae报警?
df 查看/的使用率
vim checkstorage.sh编写脚本
#!/bin/bash
[ "`df -h / | tail -n 1 | cut -d " " -f 15 | cut -d "%" -f 1`" -ge "30" ]&&{(``表示执行;[ -ge ]表示比较大小关系;)
echo "Warning: / is full!! " >> /var/log/messages如果超过负载就报警
}
at now+1min <<-EOF调用脚本时就会使得系统每分钟自动去检测/的使用率,并且去报警
/mnt/checkstorage.sh
EOF
以上命令也可以使用数组解决
a=(`df -h / | tail -n 1`)
echo ${a[4]} | cut -d "%" -f 1
df -h / | tail -n1 | awk '{print $5}'
at -l
cat /var/log/messages