1. #!/bin/bash
  2. while :  
  3. do 
  4. vmr=`vmstat | tail -1 | awk '{print $1}'
  5. if [ ${vmr} -gt 4 ]                                         #4为cpu核心数
  6. then 
  7. date   >> /root/monitor.txt 
  8. vmstat >> /root/monitor.txt 
  9. netstat -anp >> /root/monitor.txt 
  10. ps -aux>> /root/monitor.txt 
  11. last   >> /root/monitor.txt 
  12. tail -10 /var/log/messages >> /root/monitor.txt 
  13. fi 
  14. sleep 60
  15. done