I'm trying to invoke a 3rd party command line tool from a launch agent to connect to a server on my LAN. It seems impossible.
I have a little shell script that does what I need, and it works fine invoked in Terminal.app. The first time I run it that way I get permission prompts and I agree to them all. Subsequent invocations work.
Now I put a launch agent in ~/Library/Launch Agents. It does nothing more than invoke my shell script at some specific time daily. launchd launches it, but it fails to access the LAN, with a 'no route to host' error message.
The command line tool I'm trying to use is not a macOS-provided one, but one from MacPorts/HomeBrew (I tried both). It doesn't even matter which tool I'm using, I tried a very simple case of just using nc/netcat. If I use the macOS-provided nc, then I can access my LAN. If I install nc from MacPorts /HomeBrew, that nc cannot access my LAN.
This I've reproed on a literally brand new Mac, then updated to newest Sequoia (15.3.2), then done all I've described above.
I've ruled out DNS by working with raw IP addresses.
I've disabled gatekeeper with sudo spctl --master-disable.
I've tried using cron instead of launch agents, same results.
I've tried codesigning with codesign -dvvv /opt/homebrew/bin/nc, no help.
I've read TN3179 Understanding local network privacy.
In summary:
Terminal.app -> script -> macOS/brew nc -> internet/LAN = works
launchagent -> script -> macOS nc -> internet = works
launchagent -> script -> macOS nc -> LAN = works
launchagent -> script -> brew nc -> internet = works
launchagent -> script -> brew nc -> LAN = fails
How can I make that last case work?
Topic:
App & System Services
SubTopic:
Networking