我正在尝试编写一个脚本来检查 mysql 是否正在运行,如果没有,则重新启动它......
如果从终端手动调用,我可以完美地运行一个脚本,但是当我将其添加到 crontab 时,它的输出却完全不同......
代码是
service mysql status
当从终端运行时它只输出
mysql start/running, process 2570
但当它从 crontab 运行时它会输出
/usr/bin/mysqladmin Ver 8.42 Distrib 5.5.41, for debian-linux-gnu on x86_64 Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Server version 5.5.41-0ubuntu0.14.04.1-log Protocol version 10 Connection Localhost via UNIX socket UNIX socket /var/run/mysqld/mysqld.sock Uptime: 14 min 9 sec Threads: 1 Questions: 2220 Slow queries: 0 Opens: 684 Flush tables: 1 Open tables: 170 Queries per second avg: 2.614
看来 crontab 版本调用 /usr/bin/mysqladmin 而不是 mysql
我怎样才能改变这一点?
答案1
您可以尝试在其中输入以下段落:
noadm="false"
noadm=(v)
并到mysql -v
这样也许能很好地发挥作用。