I must first of all shamefully admit that I unfortunately know nothing about scripts... I am simply trying to use one that seems to fit my goal.
I am running a VPS node with OpenVZ, and I need a script which will automatically restart the VPS abusing the server load by using the specific command "vzctl restart SERVERID".
However, I'm getting nowhere unfortunately and the script returns errors when launched.
The original script is as follows:
#! /bin/bash
export PATH="/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin"
maxload="20"; # put here the max loadavg permitted
cat /dev/null > loads.txt;
vzlist -o ctid,laverage > loads.txt;
cat loads.txt | while read line; do
vm=$(echo ${line:0:5});
load=$(echo ${line} | cut -d'/' -f3);
load2=$(echo ${load} | cut -d'.' -f1);
if [ $load2 -gt $maxload ]
then
echo "restarting $vm - $load";
vzctl restart $vm;
echo "$vm - $load" | mail -s "$vm restarted for overload" hostingstudio.net@gmail.com
fi
done
If I launch it, I get this error:
antiload.sh: line 10: [: too many arguments
I researched a bit on the Internet, and I then tried isolating the variable on line 10 with quotes, thus changing the code like this:
if [ "$load2" -gt $maxload ]
but I still get an error, as follows:
antiload.sh: line 10: [[: CTID LAVERAGE: syntax error in expression (error token is "LAVERAGE")
Please, can someone help me to debug this script so that I will be able to use it?
Thanks for your attention, time and help.