Put the following script in a .sh file, for example in /root/reboot-load.sh
.
#!/usr/bin/bash
LOAD=`uptime |awk '{print $NF}'`
LOADCOMP=`echo "($LOAD * 100) / 1" | bc`
echo "Load is: $LOAD"
if [[ $LOADCOMP -ge 2000 ]]
then echo "Greater than 20 ! Reboot !"
fi
if [[ $LOADCOMP -ge 2000 ]]
then reboot
fi
As the user root, run command crontab -e
and add a cron job for this:
*/5 * * * * bash /root/reboot-load.sh
This will check every 5 minutes if the average load for 15 min is greater than 20.00
If you want to change the limit, for example to 1.52 load, multiply by 100 (result will be 152) and change it in the lines with if:
if [[ $LOADCOMP -ge 152 ]]
If you want to use the load average for 5 min replace the second line with this:
LOAD=`uptime |awk '{print $(NF-1)}' FS=,`
If you want to use the load average for 1 min replace the second line with this:
LOAD=`uptime |awk '{print $(NF-2)}' |awk '{print $1}' FS=,`