#! /bin/bash
read -p "please input the thread name you want to monitor: " threadname
echo "name is $threadname"
read -p "please input the second you monitor: " second
filename=`date +%F`"log.txt";
echo "filename $filename"
#死循环
while true
do
#获得时间
MyTime=`date +%F%r`
#获得内存
MemInfo=`free -m|grep Mem|awk '{print " total: " $2,"use: "  $3,"free: " $4}'`
MemInfo=${MyTime}${MemInfo}
echo $MemInfo >> $filename
#获得top命令监控信息
TopInfo=`top -b -n 1 |grep -w $threadname|awk '{print "\n"," cpu :",$9," mem: ",$10,$11,$12,"\n"}'`
echo $TopInfo >> $filename
#睡眠时间
sleep $second
done