'service mysql status' returns different values

July 13, 2014 886 views

I have a simple bash script running the following command:

service mysql status | mail -s "MySQL service" myname@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?

1 Answer

I found my answer here:


Basically the cron jobs operate in a limited environment, so in 'start [service]', the start command is not found!

In my case, the 'service' command is part of the 'Upstart' daemon of Ubuntu, and by default the cron process doesn't have the path to it.

Adding the following to my bash script fixed the issue:


Have another answer? Share your knowledge.