我想要一个 bash shell 脚本,我可以使用 cron 作业运行它来检查远程服务器上的 mysql 是否正在运行。如果是,则什么都不做,其他启动服务器。
cronjob 将每分钟检查远程服务器是否存在实时(或非)mysql。我可以自己编写 cron 作业,但我需要有关检查远程 mysql 是否启动或关闭的 shell 脚本的帮助。检查后的响应是向上还是向下并不重要。但是检查很重要。
您可以使用以下脚本
#!/bin/bash
USER=root
PASS=root123
mysqladmin -h remote_server_ip -u$USER -p$PASS processlist ###user should have mysql permission on remote server. Ideally you should use different user than root.
if [ $? -eq 0 ]
then
echo "do nothing"
else
ssh remote_server_ip ###remote server linux root server password should be shared with this server.
service mysqld start
fi
Run Code Online (Sandbox Code Playgroud)