1

I have a script that works when called:

/usr/local/bin/myscript #this works fine

Permissions for the file are:

-rwxr-xr-x 1 root root 155 Jan 27 09:34 myscript

I've added a line to /etc/crontab:

* * * * * root /usr/local/bin/myscript

But cron doesn't seem able to run this.

The crontab has the PATH variable set:

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

The script is a mysqldump to the /var/tmp/ directory:

#!/bin/bash

DAY=`date +%y%m%d`
TIME=`date +%k%M`
mysqldump test -u john -pxxxxxxx > /var/tmp/$DAY.$TIME.test.sql

I can't think what is wrong with this, but the script isn't running.

Edit: /var/log/syslog shows the following entries:

Jan 27 10:20:01 hector CRON[8286]: (root) CMD (/bin/bash /usr/local/bin/myscript)
Jan 27 10:20:01 hector CRON[8285]: (CRON) info (No MTA installed, discarding output)

So I guess it's trying to run the script, but it must be failing somewhere because I don't get the same output as if I ran it with /usr/local/bin/myscript.

1 Answers1

1

I'd guess (with the lacking debug info) that this is a restricted environment/path issue, which you seem to have partially tried to address.

Update /usr/local/bin/myscript to include use full paths something like:

#!/bin/bash

DAY=`/bin/date +%y%m%d`
TIME=`/bin/date +%k%M`
/usr/bin/mysqldump -u john -pxxxxxxx test > /var/tmp/$DAY.$TIME.test.sql

(I expect the date full path is overkill, mysqldump is the key one see:whereis mysqldump on your system)

Rudu
  • 301