使用方法:spa
能夠在/etc/rc.local 中添加命令:.net
sh /root/cpu_test/test_reboot.sh &code
兩個腳本要放在同一文件夾下。注意文件位置。blog
主腳本中的「4」 就是開機次數。能夠自行修改。get
主腳本:it
#! /bin/bash # filename: test_reboot.sh cores=`cat /proc/cpuinfo| grep "cpu cores" | awk -F ' ' '{print $4}'| uniq` echo `date +"%Y-%m-%d %H:%M:%S"` "power on" >> /root/cpu_test/reboot.log sleep 1 A=`cat /root/cpu_test/reboot.log | grep "power on" | wc -l` if [ $A -gt "4" ] then echo "power on " $A "times" >> /root/cpu_test/reboot.log else sleep 30 sh /root/cpu_test/all_cpu.sh $cores & sleep 1m reboot fi
cpu滿載腳本:
#! /bin/bash # filename: all_cpu.sh if [ $# != 1 ] ; then echo "USAGE: $0 <CPUs>" exit 1; fi for i in `seq $1` do echo -ne " i=0; while true do i=i+1; done" | /bin/sh & pid_array[$i]=$! ; done for i in "${pid_array[@]}"; do echo 'kill ' $i ';'; done