Chinaunix首页 | 论坛 | 博客
  • 博客访问: 21779
  • 博文数量: 5
  • 博客积分: 1512
  • 博客等级: 上尉
  • 技术积分: 75
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-23 23:18
文章分类

全部博文(5)

文章存档

2011年(4)

2008年(1)

我的朋友

分类: LINUX

2011-05-06 08:33:08

测试机使用的用户太多,经常引致内存不足,却又没有事先告警,使得系统无法工作。 本脚本能在内存将要耗尽前提示给所有用户,以便各用户可做一些工作释放内存或者及时保存各自的资料以免系统崩溃时丢失。
 
用root登录,crontab -e编辑,在最后一行加上下面这条命令(注意路径要改成你的):
0,15 8-20 * * * /home/me/shell/mem_detect.sh
 
上面命令表示每天8-20点,每隔15分钟运行一次/home/me/shell/mem_detect.sh,如果运行时物理内存使用率超过98且pg使用率超过70%(在脚本实现)就wall。
 
编辑上面命令的脚本:
-bash-3.2# cat /home/me/shell/mem_detect.sh
#!/usr/bin/sh
 
memory_size=`svmon -G|grep memory|awk '{print $2}'`
memory_inuse=`svmon -G|grep memory|awk '{print $3}'`
 
pg_space_size=`svmon -G|grep "pg space"|awk '{print $3}'`
pg_space_inuse=`svmon -G|grep "pg space"|awk '{print $4}'`
 
memory_usage=`awk 'BEGIN {a="'$memory_inuse'"/"'$memory_size'";print a}'|cut -d. -f2|cut -b1,2`
pg_space_usage=`awk 'BEGIN {a="'$pg_space_inuse'"/"'$pg_space_size'";print a}'|cut -d. -f2|cut -b1,2`
 
if [ $memory_usage -gt 98 -a $pg_space_usage -gt 70 ]
then
        wall "memory_usage:$memory_usage%\npg_space_usage:$pg_space_usage%\n"
        wall 'System memory is going to be not enough! Please exit some unuse process now!'
fi
阅读(1333) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~