Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

edwardware

macrumors newbie
Original poster
Aug 6, 2011
5
0
Hi,

I am trying to use launchd to run a shell script backing up my box to an external HD. The script (backupmgr.sh) uses rdiff-backup, and it runs as expected when I launch it from Terminal. This script includes email reporting to email me results of my backup attempt.

I modified an example .plist to run this script at 0330 every day. The .plist is in ~/Library/LaunchAgents, so it will only run when I'm logged in.

My problem is that, although the script runs perfectly from the Terminal, it fails (/Users/mindlab/backup/backup.sh: line 32: rdiff-backup: command not found) when launchd runs it. I cannot figure out why! How could a command be 'not found' from launchd when it works from Terminal?

I've attached the .plist below. Any help would greatly appreciated.

Code:
<?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.mindlab.backup</string>
	<key>LowPriorityIO</key>
	<false/>
	<key>Nice</key>
	<integer>1</integer>
	<key>AbandonProcessGroup</key>
	<true/>
	<key>OnDemand</key>
	<true/>
	<key>ProgramArguments</key>
	<array>
		<string>/Users/mindlab/backup/backupmgr.sh</string>
	</array>
	<key>StartCalendarInterval</key>
	<dict>
		<key>Hour</key>
		<integer>3</integer>
		<key>Minute</key>
		<integer>30</integer>
	</dict>
</dict>
</plist>
 
To run a shell script, you have to make it run is via sh first (see red). Make it like this:
Code:
<?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.mindlab.backup</string>
	<key>LowPriorityIO</key>
	<false/>
	<key>Nice</key>
	<integer>1</integer>
	<key>AbandonProcessGroup</key>
	<true/>
	<key>OnDemand</key>
	<true/>
	<key>ProgramArguments</key>
	<array>
		[COLOR="Red"]<string>/bin/sh</string>[/COLOR]
		<string>/Users/mindlab/backup/backupmgr.sh</string>
	</array>
	<key>StartCalendarInterval</key>
	<dict>
		<key>Hour</key>
		<integer>3</integer>
		<key>Minute</key>
		<integer>30</integer>
	</dict>
</dict>
</plist>
 
Intell: I've read about needing to add the shell path, and I've tried it. I just tried it again as you've noted; it still doesn't work!

Edit: Yes, sh is the correct shell. The script works fine from Terminal in the sh shell.

Any other ideas?

To run a shell script, you have to make it run is via sh first (see red). Make it like this:
Code:
<?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.mindlab.backup</string>
	<key>LowPriorityIO</key>
	<false/>
	<key>Nice</key>
	<integer>1</integer>
	<key>AbandonProcessGroup</key>
	<true/>
	<key>OnDemand</key>
	<true/>
	<key>ProgramArguments</key>
	<array>
		[COLOR="Red"]<string>/bin/sh</string>[/COLOR]
		<string>/Users/mindlab/backup/backupmgr.sh</string>
	</array>
	<key>StartCalendarInterval</key>
	<dict>
		<key>Hour</key>
		<integer>3</integer>
		<key>Minute</key>
		<integer>30</integer>
	</dict>
</dict>
</plist>
 
My problem is that, although the script runs perfectly from the Terminal, it fails (/Users/mindlab/backup/backup.sh: line 32: rdiff-backup: command not found) when launchd runs it. I cannot figure out why! How could a command be 'not found' from launchd when it works from Terminal?

I've attached the .plist below. Any help would greatly appreciated.

Code:
<?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.mindlab.backup</string>
	<key>LowPriorityIO</key>
	<false/>
	<key>Nice</key>
	<integer>1</integer>
	<key>AbandonProcessGroup</key>
	<true/>
	<key>OnDemand</key>
	<true/>
	<key>ProgramArguments</key>
	<array>
		<string>/Users/mindlab/backup/[COLOR="red"]backupmgr.sh[/COLOR]</string>
	</array>
	<key>StartCalendarInterval</key>
	<dict>
		<key>Hour</key>
		<integer>3</integer>
		<key>Minute</key>
		<integer>30</integer>
	</dict>
</dict>
</plist>
 
Actually backupmgr.sh manages the email reporting, and backup.sh does the backup. That part works.

I've attached the .plist below. Any help would greatly appreciated.

Code:
<?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.mindlab.backup</string>
	<key>LowPriorityIO</key>
	<false/>
	<key>Nice</key>
	<integer>1</integer>
	<key>AbandonProcessGroup</key>
	<true/>
	<key>OnDemand</key>
	<true/>
	<key>ProgramArguments</key>
	<array>
		<string>/Users/mindlab/backup/[COLOR="red"]backupmgr.sh[/COLOR]</string>
	</array>
	<key>StartCalendarInterval</key>
	<dict>
		<key>Hour</key>
		<integer>3</integer>
		<key>Minute</key>
		<integer>30</integer>
	</dict>
</dict>
</plist>
 
Solution!

Folks: thanks for the input, etresoft and BobHarris over at discussions.apple.com solved it. My PATH included /opt/local/bin, and launchd's PATH does not. As soon as I specified the full command PATH, the script works under launchd.

Cheers!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.