run.sh
#!/bin/bash dir=`dirname "$0"` today=`date +%Y-%m-%d` cd "$dir" echo "$$" > run.pid if [ ! -d dat ];then mkdir dat fi vmstat 1|stdbuf --output=0 sed -e "1d" -e "/^\\s*\(procs\|r\)/d" |stdbuf -oL awk '{if($15<50||$4<1048576) print strftime("%H:%M:%S")" X "$0; else print strftime("%H:%M:%S")" N "$0;}' >> "dat/$today.log" 2>err.log
reboot.sh
#!/bin/bash dir=`dirname "$0"` cd "$dir" oldlogs=`find ./ -mtime +30 -name "*.log"|wc -l` find ./dat/ -mtime +30 -name "*.log" -exec rm -rf {} \; echo "delete old log :$oldlogs files" pid=`cat run.pid` ps --ppid $pid|sed "1d"|awk '{print $1}'|xargs kill -9 kill -9 $pid echo "killed pid $pid" nohup ./run.sh > /dev/null 2>err.log & echo 'done'