0

I have a Python script scheduler.py to monitor and record network metrics using a few different tests, with iperf being one of them. I need this script to run on boot up, which is why I have set up a LaunchAgent with the RunAtLoad flag set to true. The scheduler script is executed by launchctl as intended, except for when the iperf3 commands are to be run. I am logging the errors of the LaunchAgent, and below are the errors logged:

/bin/sh: iperf3: command not found 
/bin/sh: iperf3: command not found 
/bin/sh: iperf3: command not found 
/bin/sh: iperf3: command not found 

I am pretty sure that the paths being used when running the script through terminal vs. running the script through launchctl is very different, but I just can't seem to figure out where to make the fix.

Here's what I have tried:

  1. Confirmed the paths of Python and iperf3 installation as /opt/homebrew/bin/python3 and /opt/homebrew/bin/iperf3 respectively.

  2. Updated iperf3 installation with brew reinstall iperf3

  3. Added complete python path to my plist file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>scheduler</string>

    <key>RunAtLoad</key>
    <true/>

    <key>ProgramArguments</key>
    <array>
        <string>/opt/homebrew/bin/python3</string>
        <string>/full/path/to/file/scheduler.py</string>
    </array>

    <key>StandardOutPath</key>
        <string>/full/path/to/file/service_stdout.log</string>

    <key>StandardErrorPath</key>
        <string>/full/path/to/file/service_error.log</string>
</dict>
</plist>
  1. Added the shebang #!opt/homebrew/bin/python3 at the start of my script.

  2. There was a similar problem reported while programmatically accessing the Bear CLI through a shell script here, but I am unsure how to adapt the solution to my Python script.

Any help would be appreciated, I've been struggling with this for weeks as I'm new to LaunchAgent and MacOS! Thanks.

0 Answers0