I have a MySQL DB running on a Debian machine in GCP, which sometimes reaches the limit of connections, which leaves the application stopped until it is restarted and then the application can be reconnected.
Currently has a maximum number of connections has 1000, my idea was to create a script that would look at the database to get the number of connections and if it exceeded 950 restart the database. the idea is to put it in a Crontab that runs every 5 minutes.
At the moment what I have been up to here and I have not managed to make it work anymore (I'm a blanket :)) The two data connections are for tests, restart when there are more than three connections.
sudo mysql < in.txt > out.txt;
sudo grep -o '[0-9]' <out.txt >connections.txt
#maxconnections=$(cat connections.txt)
maxconnections=$(awk '{ print $1 }' connections.txt)
echo $maxconnections
sleep 4
if [[$maxconnections -ge "3"]]; then service mysql restart
else
echo "por debajo de las conexiones maximas"
sleep 3
fi ;
The file in.txt has the following command:
show status where 'variable_name' = 'Threads_connected';
The file out has the result of executing the file command in.txt:
Variable_name Value
Threads_connected 2
The connections file only contains the number of connections, in contract: 2
When executing the script I get the following error:
root@test-mysql:/home/aminiasin/temp# ./script.sh
2
./script.sh: line 11: [[2: command not found
one or less
root@test-mysql:/home/aminiasin/temp#
Any clue as to why it may be failing?