I have the following script, which when I break it down it works. However when I run it it tell me that mysql is not running. and starts the mysql server.
When I run pgrep mysqld | wc -l
pgrep mysqld | wc -l
it returns 2 but for some reason the script still runs
echo "MySQL is down.";
service mysqld start
Here is the original script.
#!/bin/bash
UP=$(pgrep mysqld | wc -l);
if [ "$UP" -ne 1 ];
then
echo "MySQL is down.";
service mysqld start
else
echo "All is well.";
fi
You are testing the output for 1, but it returns 2 as you wrote. Change -ne condition to -lt.
Anyway, I would use something like this, to see the mysql status, instead of the pgrep: service mysql status
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.