MacOS: trying to load evicted file from launch'd shell script, leading to resource deadlock error

On MacOS Sonoma (14.5) with iCloud synchronization switched on, I am trying to access or load a file in a (bash) shell script. Simply via:


cat DSC_0001.jpg >/dev/null


(Note that this simple line of code is for me the reproducible example. DSC_0001.jpg is just an example file, the problem described here appears for all files, as long as other conditions hold, as described below.)


This line of (shell) code works perfectly fine when I do this in a terminal, even if the file is "evicted" to iCloud.


As far as I understand, a file is "evicted" to iCloud when iCloud uploaded it to the cloud, but deleted the local copy, so that it is no longer physically stored on my machine, but on the cloud. In Finder, such files are marked with a cloud and arrow symbol.


I need to work with such evicted files, in a shell script that I run in the background, as a launch'd agent, via launchctl and a plist configuration file in ~/Library/LaunchAgents . (Note that ultimately, I want to backup the file and many others via rsync, not just cat the file as in the example above, but this one seems to be the simplest reproducible version of my problem.)


Now my problem is, that if the file is evicted, AND if I run the above command in a launch'd script, then the command throws the following error:


cat: DSC_0001.JPG: Resource deadlock avoided


How can I get rid of this error, and access or load the evicted file in my launch'd script?

Posted on Jan 12, 2025 7:26 AM

Reply

Similar questions

2 replies

Jan 12, 2025 10:37 AM in response to hansschl2

You may want to give this a look over (in particular the troubleshooting section where it discusses certain things you normally do in shell scripts that you cannot do with launchd): https://launchd.info/


Also keep in mind that when you launch the Terminal, you get any personalized configurations you have brought in through your interactive shell settings (.bashrc, .zshrc, etc depending on your shell and how you set it up). Launchd expects 100% POSIX compliant bare non-interactive "sh" for it's environment and anything else is set up in the .plist itself, which would then make appropriate system calls to another shell.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

MacOS: trying to load evicted file from launch'd shell script, leading to resource deadlock error

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.