Script of mysqldump didn't work correct invoked by launchctl in OS X Here is my question asked on StackExchange 2 days ago. https://stackoverflow.com/q/35839190/4772652 
Someone suggested me to ask here. Could anyone give me a hand to solve this?

============

I had tried to launch a script of mysqldump for daily backup by launchd and also by Carbon Copy Cloner (CCC). The script works fine under command line. However, it comes with empty file under launchd or CCC.

While I manually ran the command sh mysqldump.sh, a &lt;DATE&gt;.sql.gz file will be created. And if the launchd/CCC called the script, a &lt;DATE&gt;.sql.gz file will also be created. However, the file size will by 2 0B.

Here is the content of my plist file

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
    &lt;dict&gt;
        &lt;key&gt;Label&lt;/key&gt;
        &lt;string&gt;com.MySQL.crontab&lt;/string&gt;
        &lt;key&gt;Program&lt;/key&gt;
        &lt;string&gt;/bin/mysqldump.sh&lt;/string&gt;
        &lt;key&gt;RunAtLoad&lt;/key&gt;
        &lt;true/&gt;
        &lt;key&gt;StandardErrorPath&lt;/key&gt;
        &lt;string&gt;/tmp/AlTest1.err&lt;/string&gt;
        &lt;key&gt;StandardOutPath&lt;/key&gt;
        &lt;string&gt;/tmp/AlTest1.out&lt;/string&gt;
        &lt;key&gt;StartCalendarInterval&lt;/key&gt;
        &lt;dict&gt;
            &lt;key&gt;Weekday&lt;/key&gt;
            &lt;integer&gt;5&lt;/integer&gt;
            &lt;key&gt;Hour&lt;/key&gt;
            &lt;integer&gt;6&lt;/integer&gt;
            &lt;key&gt;Minute&lt;/key&gt;
            &lt;integer&gt;0&lt;/integer&gt;
        &lt;/dict&gt;
    &lt;/dict&gt;
&lt;/plist&gt;


And the launchd status for this plist is - 0   com.MySQL.crontab

Here is the script for mysqldump, which is created by Schulz with slight modified

#!/bin/sh
# *************************************************************
# file: mysqldump.sh
# date: 2015-03-27
# author: (c) by Marko Schulz - &lt;info@tuxnet24.de&gt;
# description: Get a mysqldump of all mysql databases.
# *************************************************************

dbUsername="me"
dbBackup="/Backup/MySQL_backup"

date=$( date +%Y%m%d )

find $dbBackup/ -mtime +30 -type f -name '*.sql.gz' -exec rm -rf {} ';' &gt;/dev/null 2&gt;&amp;1

mysqldump -u $dbUsername --all-databases | gzip &gt; ${dbBackup}/${date}.sql.gz 2&gt;&amp;1


What could I do to solve this problem?
Your shell script is missing the full path to mysqldump (assuming you've installed MySQL Community Edition by Oracle):

/usr/local/mysql/bin/mysqldump -u $dbUsername --all-databases | gzip &gt; ${dbBackup}/${date}.sql.gz 2&gt;&amp;1


If you need a password define it in the shell script:

dbPassword="my_dbuser_password"


and change the above line to:

/usr/local/mysql/bin/mysqldump -u $dbUsername -p$dbPassword --all-databases | gzip &gt; ${dbBackup}/${date}.sql.gz 2&gt;&amp;1


There is no space between -p and $dbP...!

I also advice to move the shell script to another path (e.g. /usr/local/bin/). You have to adjust your plist then and the line

    &lt;string&gt;/bin/mysqldump.sh&lt;/string&gt;


becomes:

    &lt;string&gt;/usr/local/bin/mysqldump.sh&lt;/string&gt;