I have a simple bash script running the following command:
service mysql status | mail -s "MySQL service" firstname.lastname@example.org
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:
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.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?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
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.
Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.
Click below to sign up and get $100 of credit to try our products over 60 days!