sam
sam

Reputation: 193

mysql will not start from cron job

/etc/init.d/mysql start
works when executing through shell command
works when put in a bash script, and then executing the bash script
However when i try to execute this script from a cronjob
I get this error
/etc/init.d/mysql: 73: start: not found
Any explanations and how i could fix this.
I am on Ubuntu 10.0
oilChange.sh
#!/bin/bash
service apache2 stop
sleep 1s
/etc/init.d/mysql stop
sleep 1s
/sbin/swapoff -a
sleep 1s
/sbin/swapon -a
sleep 1s
/etc/init.d/mysql start
sleep 1s
if [
pgrep mysql -c-le "0" ]; then /etc/init.d/mysql start; fi
sleep 1s
service apache2 start
sleep 1s
if [
pgrep apache -c-le "0" ]; then service apache2 start; fi
sleep 1s
cd /root/crt
php twatch3.php

This is what gets logged in /var/mail/root

    Subject: Cron <root@cloud> bash /root/crt/oilChange.sh
Content-Type: text/plain; charset=ANSI_X3.4-1968  

    X-Cron-Env: <SHELL=/bin/sh>  
    X-Cron-Env: <HOME=/root>  
    X-Cron-Env: <PATH=/usr/bin:/bin>  
    X-Cron-Env: <LOGNAME=root>  

 * Stopping web server apache2
 ... waiting    ...done.
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service mysql stop

Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the stop(8) utility, e.g. stop mysql
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service mysql start

Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the start(8) utility, e.g. start mysql
/etc/init.d/mysql: 73: start: not found
 * Starting web server apache2
   ...done.

root@cloud:~#

I have tried  
service mysql stop 
stop mysql 
Both work from cmd prompt, and
script execution from cmd prompt but
fail when the script is executed by the cron

Upvotes: 0

Views: 2183

Answers (2)

David Harris
David Harris

Reputation: 2340

The crontab man page states that the PATH variable is set to a value that is guaranteed to find all the standard utilities. Update and export the path variable to include all utilities.

Upvotes: 1

Nanne
Nanne

Reputation: 64409

It might be because it is not a script, it's a script with an added paramter. You might need " or something like that.

Upvotes: 0

Related Questions