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.

5
  • 2
    Did you check this ? serverfault.com/questions/449651/…
    – krisFR
    Jan 27, 2014 at 10:25
  • Yes, I've checked that - I think I've addressed the points made in that post.
    – babbaggeii
    Jan 27, 2014 at 10:29
  • 2
    You have no log on the reason why it does not work beacause you have "no MTA installed" either install postfix or replace * * * * * root /usr/local/bin/myscript by * * * * * root /usr/local/bin/myscript > /path/to/examplelog 2>&1 ;;; you'll then be able to get a clue.
    – user130370
    Jan 27, 2014 at 10:31
  • Work your way through the document linked to above, it will almost certainly help you solve your problem and even if it doesn't it will help you gather information that will help you help us solve the problem.
    – user9517
    Jan 27, 2014 at 10:35
  • I suggest you install an MTA so you can get the output. Jan 27, 2014 at 14:08

1 Answer 1

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)

0

Not the answer you're looking for? Browse other questions tagged .