Your condition test must execute some sort of code if true.
It looks like you want to reboot
if "$PORT"
is not "3306"
.
You should only use break
when testing a condition, otherwise the loop will only execute once.
The PORT
variable will not update unless you call the code that sets it again after you need it to update.
Also, you don't need to use grep
when you are using awk
.
#!/bin/bash
callport ()
{
PORT=`netstat -na|awk -F[:" "]+ '/LISTEN/ && /3306/ {print $5}'`
}
MYSQLIP=`ifconfig eth0|awk '/inet/{print $2}'|cut -c 6-`
while [ `whoami` == "root" ]
do
callport
if [ "$PORT" == "3306" ];then
echo "mysql is running......"
break
else
service mysql restart
callport
if [ "$PORT" != "3306" ];then
reboot
fi
fi
done