Sample Header Ad - 728x90

Cron and launchd rsync/ssh job do not work when screen is locked

1 vote
0 answers
135 views
I have implemented a bash script to perform a backup to a remote server over ssh using rsync. Running the script in the terminal works correctly. I then scheduled a crontab job to run this script twice a week. When I'm logged in, with the screen unlocked, the job runs correctly at the specified time. However, if the screen is locked some bash commands before the rsync run correctly, but then the rsync connection fails:
xxxxx  rsync error: unexplained error (code 255) at io.c(231) [sender=3.2.7]
xxxxx  rsync: connection unexpectedly closed (0 bytes received so far) [sender]
I also scheduled it using launchd and the behavior is the same. Searching a bit I found this might be related to the ssh connection not working when the screen is locked. How can make ssh to work, either with crontab or launchd, even when the screen is locked? In case is useful information I did have to add this in the bash script to make it work with the ssh agent:
declare -x SSH_AUTH_SOCK=$( ls /private/tmp/com.apple.launchd.*/Listeners )`
The MacOS version I'm using is Mojave 10.14.6. Thank you.
Asked by Alan M. (11 rep)
Dec 20, 2023, 07:14 PM
Last activity: Dec 21, 2023, 08:20 AM