I'm trying to write a script that checks if mysql is running, and if not restart it...

i get a script to run perfectly if is called manually from terminal, but when i added to crontab it outputs is totally different...

the code is

service mysql status

when run from terminal it just outputs

mysql start/running, process 2570

but when it runs from crontab it outputs

/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

it seems that the crontab version calls /usr/bin/mysqladmin instead of mysql

how can i change this?

  • Not a direct answer, just 2 advices about crontab. The environment used for cron is limited and different then bash with logged user. Usually the command line during cron script run is not bash (in Ubuntu is dash, not sure in Debian). So two tips: test in the same command line interpreter used by crontab (or change the sha-bang to use bash); and if possbile, provide full paths. – Rael Gugelmin Cunha Apr 11 '15 at 0:43
  • No, don't do that (change the shell for cron), use the full path to binaries you want to call. So use /use/bin/mysql rather the mysql . See help.ubuntu.com/community/CronHowto – Panther Apr 11 '15 at 2:09

You could maybe try enter this paragraph to it:


and to the mysql -v

and it might work fine this way.

  • It know outputs "Usage: /etc/init.d/mysql start|stop|restart|reload|force-reload|status" when i call "service mysql -v status" – Lcross Portugal Apr 11 '15 at 0:53
  • with the noadm=(v) it doesn't log anything after it... – Lcross Portugal Apr 11 '15 at 1:16

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.