Put the following script in a .sh file, for example in /root/watch-mysql.sh
#!/usr/bin/bash
trap "exit" 0
MAXCONN=1000 # set this to whatever base max_connections you have defined in your my.conf setting
while true; do
#mysql -e "SHOW VARIABLES LIKE 'max_connections';"
THREADS=`mysqladmin status | awk '{print $4}'`