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

costabunny

macrumors 68020
Original poster
May 15, 2008
2,466
71
Weymouth, UK
I have my backup shell script and it works as expected when run from the cli. It also runs ok from its LaunchAgent entry (in ~/Library/LaunchAgents/)

The problem is that the script uses /usr/bin/mail at the end of a run to send the content of the summary log to myself. When running from the prompt this is successful; however when running from launchd it simply does not send the email. the mail logs show no attempt at all from the script.

Any ideas?

Code:
~/Library/LaunchAgents/com.local.lokibackup.plist 


<?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.local.lokibackup</string>
    	<key>ProgramArguments</key>
    <array>
        <string>/Users/MYUSER/Scripts/backup.sh</string>
    </array>
    
	<key>StartCalendarInterval</key>
    <dict>
		<key>Weekday</key>
			<integer>1</integer>
		<key>Hour</key>
			<integer>16</integer>
		<key>Minute</key>
			<integer>10</integer>

	</dict>
	<key>UserName</key>
	<string>MYUSER</string>		
</dict>
</plist>
 
Last edited:

costabunny

macrumors 68020
Original poster
May 15, 2008
2,466
71
Weymouth, UK
wow 144 views and no answers - u guys :)

well I've not been sitting here waiting for an answer, but I have finally found the info needed on this site.

its all about launchd and the way it kills all child processes started by a script its handling. In my case its killing off sendmail :(

so adding a key telling not to do this was the answer:

Code:
	<key>AbandonProcessGroup</key>
		<true/>

Nows its running fine as well as sending my report :) Happy Bunny
 

costabunny

macrumors 68020
Original poster
May 15, 2008
2,466
71
Weymouth, UK
So next problem

My script is working 100%. My launch agent is good except one little niggle.

it runs the first backup at the time specified, but never seems to start again. I experimented with the keepalive option (dumb - kept launching the script again and again).

If I unload the plist and reload it it will trigger at the next time instance set, then it won't the next day.

Any ideas folks? This is driving me nuts. I just want the launch agent to trigger the backup script at a specified time (06:30) every day.

permissions etc must be correct (else it wouldn't execute the first time).

this is my LaunchAgent

com.local.lokibackup.plist
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.local.lokibackup</string>
    
	<key>ProgramArguments</key>
    	<array>
        	<string>/Users/myuser/Scripts/backup.sh</string>
    	</array>		
	
	<key>StandardOutPath</key>	
		<string>/Users/myuser/Scripts/report.txt</string>
	
	<key>StandardErrorPath</key>
		<string>/Users/myuser/Scripts/report.txt</string>    
	
	<key>StartCalendarInterval</key>
    	<dict>
			<key>Minute</key>
				<integer>06</integer>
			<key>Hour</key>
				<integer>30</integer>		
		</dict>
		
	<key>AbandonProcessGroup</key>
		<true/>
</dict>
</plist>
 

cerberusss

macrumors 6502a
Aug 25, 2013
932
364
The Netherlands
Wow, helpful stuff. Coming from the Linux side, I never took the time to really dig in and find out this side of launchd.

By the way, for the logging you could write to /var/log/yourscriptname.log. Then it nicely gets compressed and rotated. You'd have to add the new log file its name to newsyslog.conf I guess.
 

costabunny

macrumors 68020
Original poster
May 15, 2008
2,466
71
Weymouth, UK
Wow, helpful stuff. Coming from the Linux side, I never took the time to really dig in and find out this side of launchd.

By the way, for the logging you could write to /var/log/yourscriptname.log. Then it nicely gets compressed and rotated. You'd have to add the new log file its name to newsyslog.conf I guess.

My script already logs to its own logs ;)

the redirection of outputs in the plist is for the rsync output to a file that can be emailed as a summary :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.