Welcome to the JaguarPC Community
JaguarPC
Sales: (888) 338-5261
Support: (888)-551-3050
Results 1 to 4 of 4

This is a discussion on cron doesn't have permission? in the VPS & Dedicated forum
I have a php script that creates a dump of MySQL and mails it out for back-up purposes. This script works fine when run through ...

  1. #1
    JPC Addict
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    135

    cron doesn't have permission?

    I have a php script that creates a dump of MySQL and mails it out for back-up purposes. This script works fine when run through a browser, but unfortunately the MySQL dump aspect of it fails when run through a cron job (other parts of the script work, just the dump fails). I'm sure this is a permissions thing - cron doesn't have permission to do the MySQL command - but how do I fix it?

    This is the command:

    /usr/bin/mysqldump -umyusername -pmypassword --databases mydatabase | gzip > /var/www/vhosts/mydomain/httpdocs/backups/backup.sql.gz

  2. #2
    Loyal Client thisisit3's Avatar
    Join Date
    Mar 2007
    Posts
    642
    A typical problem with cron jobs is the PATH environment.

    For example, when you execute the command manually, it takes the existing PATH environment so all commands work fine.

    BUT, when cron runs the command, it has its own limited environment which has been set in the crontab. The default contains a few basic paths, thus many script commands fail.

    So, first check that you are using full paths, for example your "mysqldump" has the full path but the "gzip" command doesn't.

    As a side note, i have two suggestions:

    1) use bzip2, its much better than the old gzip (its the best 'zip' really)

    2) use the "--opt" parameter when doing sql backups, it produces a portable backup that contains all the database details needed to restore the database, "man mysqldump" for more information about it.

  3. #3
    JPC Addict
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    135
    The paths seem fine.

    Any other ideas?

  4. #4
    Loyal Client thisisit3's Avatar
    Join Date
    Mar 2007
    Posts
    642
    are you sure the command is correct and it runs fine when executed via command line?

    you could add some debug output, save stderr to a text file and read it to see what the error is.

    usually, cron grabs the stderr/stdout and emails it to you.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •