0

I have a script that runs a mysqldump and then a mysql insert from bash. It works fine from terminal, even as root (which I believe LaunchD runs as) but it will not run the mysql insert from launchd, but will run the mysqldump.

Script is:

#!/bin/bash
mysqldump -u root -pmypass my_db | gzip -9 > /path/to/dump.sql.gz
mysql -u root -pmypass my_db2 < /path/to/insert.sql

and my com.me.BackupThing.plist (from /Library/LaunchAgents), which does run and executes all but the mysql command:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.me.BackupThing</string>
    <key>ProgramArguments</key>
    <array>
        <string>/full/path/to/above/script.sh</string>
    </array>
    <key>QueueDirectories</key>
    <array/>
    <key>StartCalendarInterval</key>
    <dict>
        <key>Hour</key>
        <integer>01</integer>
        <key>Minute</key>
        <integer>00</integer>
    </dict>
    <key>WatchPaths</key>
    <array/>
    <key>UserName</key>
    <string>administrator</string>
</dict>
</plist>

All runs from terminal as root, and mysql's bin is exported on roots command path.

Why would it ignore the mysql command from launchd?

EDIT

Thanks to arco444 for solution, full path was required on mysql for some reason, new script is:

#!/bin/bash
mysqldump -u root -pmypass my_db | gzip -9 > /path/to/dump.sql.gz
/path/to/mysql/bin/mysql -u root -pmypass my_db2 < /path/to/insert.sql
Deej
  • 105
  • 1
  • 1
  • 9
  • 1
    launchd can fail to pick up environment variables that are present in a shell. Where is the mysql binary? Does it work if you specify the full path? – arco444 Feb 14 '14 at 10:08
  • It's in /usr/local/mysql/bin ... same place as the mysqldump command. Surely if that were true then it wouldn't be able to run that either? – Deej Feb 14 '14 at 10:49
  • Hey you were right @arco444, full path, and away! Mysqldump must be aliased somewhere, but mysql mustn't have been. Strange. Thanks for your help! :) – Deej Feb 14 '14 at 12:52
  • you may want to have a look on http://stackoverflow.com/a/13210563/1578528 – bikram990 Apr 17 '14 at 03:32

0 Answers0