I have a Bash script that copies a specified set of files/directories to a remote server via rsync. It is run by launchd as a Global Daemon every day at 3am. The computer is sleeping most of the time at 3am, but my understanding is that in those cases, the script will run as soon as the computer wakes.
It seems that the script is in fact running at 3am. The problem is (as far as i can tell) that the network is not active at that time, which causes the rsync command to choke. Here's the output:
***********************************************
*** BackupDaemon Running
*** 03-30-2020
*** 03:03:09 AM
***********************************************
==> stderr.log <==
ssh: Could not resolve hostname dave0112.com: nodename nor servname provided, or not known
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at /BuildRoot/Library/Caches/com.apple.xbs/Sources/rsync/rsync-52/rsync/io.c(453) [sender=2.6.9]
the hostname referenced is the remote server and is available 24/7
and here's my plist file in case it helps:
<?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>Disabled</key>
<false/>
<key>EnvironmentVariables</key>
<dict>
<key>HOME</key>
<string>/Volumes/Norman Data/daveh0</string>
</dict>
<key>GroupName</key>
<string>staff</string>
<key>InitGroups</key>
<false/>
<key>Label</key>
<string>LaunchdTest</string>
<key>Program</key>
<string>/Volumes/Norman Data/daveh0/Scripts/backup/backup</string>
<key>ProgramArguments</key>
<array>
<string>/bin/launchctl</string>
<string>setenv</string>
<string>HOME</string>
<string>/Volumes/Norman Data/daveh0</string>
</array>
<key>StandardErrorPath</key>
<string>/Volumes/Norman Data/daveh0/Scripts/backup/stderr.log</string>
<key>StandardOutPath</key>
<string>/Volumes/Norman Data/daveh0/Scripts/backup/stdout.log</string>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>3</integer>
<key>Minute</key>
<integer>0</integer>
</dict>
<key>UserName</key>
<string>daveh0</string>
</dict>
</plist>
The script runs fine if I run it manually from LaunchControl any time the computer is awake. Am I off with my belief that the script should wait until the computer is awake to run or is it something entirely different that I'm missing?
launchdwould run the script as soon as it wakes up. However this is not what's happening. It's running while the computer is sleeping (perhaps it wakes up to run the script?) but the network is not up. I'd rather the script run when I first sit down at the computer for the day, which is how I believedlaunchdbehaved. Is this inaccurate? Am I missing something in my plist file to specify this? – Daveh0 Mar 30 '20 at 19:28