kill掉名字为app_name的程序:
ps -ef | grep app_name| kill `awk '{print $2}'`
监控程序并自动重启:
RootDir=`pwd`
check_if_running()
{
BinName=$1
for pid in `ps aux | grep -v grep | grep $BinName | awk '{print $2}'`;do
dir=`readlink /proc/$pid/exe`
if [[ $dir == $RootDir/bin/$BinName ]]; then
return 1
fi
done
return 0
}
while :
do
check_if_running app1
a=$?
check_if_running app2
b=$?
if [[ $a == 0 ]] || [[ $b == 0 ]]; then
echo "Restart info_test!" | mail -s "info_test restart!" XXX@XXX.XXX
./restartAll.sh
fi
sleep 1
done
日志统计(行筛选--分隔符替换--打印需要的信息--信息重新计算整理--按数值排序--统计重复行):
grep "total:.*(ms)" app_name.log | sed "s/[:(]/\\t/g" | awk '{printf "%0d\n", $16/10}' | awk '{print $0 * 10}' | sort -n | uniq -c