'service mysql status' returns different values
I have a simple bash script running the following command:
service mysql status | mail -s "MySQL service" email@example.com
I have added it to the crontab of the root user:
sudo crontab -e
Using the following command:
*/1 * * * * bash /home/myname/cron/mysql.sh
And the resulting email contains this:
* /usr/bin/mysqladmin Ver 8.42 Distrib 5.5.37, 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
Server version 5.5.37-0ubuntu0.14.04.1
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/run/mysqld/mysqld.sock
Uptime: 3 hours 25 min 22 sec
These complicated statistics are are not expected value from the ‘service mysql status’ command.
When I run the batch file manually as root:
sudo bash mysql.sh
The resulting email contains the expected result:
mysql start/running, process 11928
So why is the 'service mysql status’ command returning an unexpected value when run from a batch file inside the root cron job?
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.×