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">
        <string>/Volumes/Norman Data/daveh0</string>
    <string>/Volumes/Norman Data/daveh0/Scripts/backup/backup</string>
        <string>/Volumes/Norman Data/daveh0</string>
    <string>/Volumes/Norman Data/daveh0/Scripts/backup/stderr.log</string>
    <string>/Volumes/Norman Data/daveh0/Scripts/backup/stdout.log</string>

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?

  • Just going from what you said in the text of your comment...it doesn’t matter if the host is available 24/7 if the network’s not available. Make sure the computer isn’t sleeping – Allan Mar 30 '20 at 18:21
  • @Allan the computer is sleeping most of the time at that time, but I thought if the computer is sleeping that launchd would 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 believed launchd behaved. Is this inaccurate? Am I missing something in my plist file to specify this? – Daveh0 Mar 30 '20 at 19:28
  • PowerNap doesn’t run those scripts. When you sit down at your computer, is it waking from sleep or are you logging in fresh? – Allan Apr 2 '20 at 7:40
  • waking from sleep – Daveh0 Apr 3 '20 at 8:51
  • This is only tangentially related, but rsync would not be able to connect to the remote server when called by a LaunchAgent while the computer was sleeping... It turns out that you need a passphrase-less id_rsa_... private key to make it work! See here. Cheers – Greg Sadetsky Mar 10 at 19:48

You must log in to answer this question.

Browse other questions tagged .