#!/bin/bash

dir="/auto_cron/cron-running/dp/processInfoCollection"
logdir="/mnt/diskb/auto_cron_logs/cron-running-logs/dp/processInfoCollection"

time=`date +%Y-%m-%d" "%H:%M:%S`

top -c -b -n 5 > ${dir}/file1

sed -n "$(grep -n COMMAND ${dir}/file1 | tail -1 | cut -d : -f 1),+1000p" ${dir}/file1 > ${dir}/file2

sed -i "/COMMAND/d" ${dir}/file2

cat ${dir}/file2|while read line
do
echo $line > ${dir}/file3

#cat tmp

cmd=`awk '{print $12}' ${dir}/file3`
if [[ ${cmd:0:1} != "[" ]];then
cat ${dir}/file3 >> ${dir}/file4
fi

done

sed -n '/./p' ${dir}/file4 > ${dir}/tmpfile

rm ${dir}/file*

awk '{print $1}' ${dir}/tmpfile >> ${dir}/c1
awk '{print $2}' ${dir}/tmpfile >> ${dir}/c2
awk '{print $3}' ${dir}/tmpfile >> ${dir}/c3
awk '{print $4}' ${dir}/tmpfile >> ${dir}/c4
awk '{print $5}' ${dir}/tmpfile >> ${dir}/c5
awk '{print $6}' ${dir}/tmpfile >> ${dir}/c6
awk '{print $7}' ${dir}/tmpfile >> ${dir}/c7
awk '{print $8}' ${dir}/tmpfile >> ${dir}/c8
awk '{print $9}' ${dir}/tmpfile >> ${dir}/c9
awk '{print $10}' ${dir}/tmpfile >> ${dir}/c10
awk '{print $11}' ${dir}/tmpfile >> ${dir}/c11
awk '{$1=$2=$3=$4=$5=$6=$7=$8=$9=$10=$11=""; print}' ${dir}/tmpfile >> ${dir}/c12

rm ${dir}/tmpfile

sed -i "s/^/${time}\/g" ${dir}/c1

#sed -i "s/ //g" ${dir}/c12

cat ${dir}/c12 | sed 's/^[ \t]*//g' > ${dir}/c13

paste -d "" ${dir}/c1 ${dir}/c2 ${dir}/c3 ${dir}/c4 ${dir}/c5 ${dir}/c6 ${dir}/c7 ${dir}/c8 ${dir}/c9 ${dir}/c10 ${dir}/c11 ${dir}/c13 >> ${logdir}/topMassage.log

rm ${dir}/c*

 

posted on 2017-04-10 19:44  流浪在伯纳乌  阅读(238)  评论(0编辑  收藏  举报