方法1  : top  -b >top.log

    方法2;

    path="/home/liyan/monitor"
    echo ${path}
    time=0
    while(true)
    do
        day=$(date +"%Y-%m-%d")
        if [[ ! -d ${path}/${day} ]];then mkdir ${path}/${day};fi
        let time+=1
        top|head -n 20 > ${path}/${day}/${time}
        #ps aux |grep -v "TIME COMMAND" | sort -n -k3 -r|head -n 10| awk '{print $0} END {print "USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND"}' > /data/monitor/${day}/${time}.txt
        sleep 5
        find ${path} -name "2019*\.txt" -mtime +1 -exec rm -f {} \;
    done
    ~