对linux 主机配置定时清理
对linux 主机配置定时清理
因为经常有一些脚本会执行超时,而脚本本身又没有配置超时的配置,所以就需要有个脚本来定时对超时的程序进行清理。
很简洁的小脚本,请查看
#!/bin/bash
#by wangcc
function write_log {
if [ $# != 2 ]
then
echo "Usage: "$0" need: 1. log level; 2. message !!! "$0" exit!!!"
exit 0
fi
now=`date +%Y-%m-%d-%H:%M:%S`
echo "${now}:[$1]--->>>$2<<<"
}
function check_free {
buff=`free -m | grep Mem | awk '{print $6}'`
if [[ $buff -gt 1000 ]]
then
echo 1 > /proc/sys/vm/drop_caches
sleep 2
echo 2 > /proc/sys/vm/drop_caches
write_log "INFO" "wanted clean free .......Cleaning up"
fi
}
function kill_jincheng {
ancient_pid=`ps -ef |grep -E 'ip_request|get_goubanjia_ip|get_check'|grep -v grep | awk '{print $2}'|awk BEGIN{RS=EOF}'{gsub(/\n/,"|");print}' `
pid=`ps -eo pid,tty,user,comm,lstart,etime | grep -E ${ancient_pid} | awk -F'[ :]+' '{if ($13>50) print $2}'`
for i in ${pid} ;
do
if [[ ${i} -gt 0 ]]
then
kill -9 ${pid}
fi
done
}
function main {
check_free
kill_jincheng
}
main
配置定时任务
*/5 * * * * sh /root/scripts/shell/monitor/monitor.sh
大功告成
本文来自博客园,作者:Chuan_Chen,转载请注明原文链接:https://www.cnblogs.com/wangcc7/p/13648939.html