Issue with launchd Job Not Running – "Bootstrap failed: 5: Input/output error"

Purpose

I want to use launchd to run a shell script asynchronously every minute, but I'm encountering an issue where the job does not run, and I receive the error "Bootstrap failed: 5: Input/output error". I need help identifying the cause of this issue and how to configure launchd correctly.

What I've done

Created the shell script (test_ls_save.sh)

The script is designed to list the contents of the desktop and save the output to a specified directory.


#!/bin/bash

DATE=$(date +%Y-%m-%d_%H-%M-%S)

SAVE_DIR=/Users/test/Desktop/personal/log_gather

FILE_NAME="ls_output_$DATE.log"

ls ~/Desktop > "$SAVE_DIR/$FILE_NAME"

echo "ls output saved to $SAVE_DIR/$FILE_NAME"


File permissions (ls -l output): -rwxr-xr-x 1 test staff 1234 Feb 17 10:00 /Users/test/Desktop/personal/log_gather/exec/test_ls_save.sh

Created the launchd plist file (com.test.logTest.plist)

The plist file is configured to execute the shell script every minute.


<?xml version="1.0" encoding="UTF-8"?>

<plist version="1.0">

<dict>

<key>Label</key>

<string>com.test.logTest</string>

<key>ProgramArguments</key>

<array>

  <string>/bin/bash</string>

  <string>-c</string>

<string>/Users/test/Desktop/personal/log_gather/exec/test_ls_save.sh</string>

</array>

<key>StartInterval</key>

<integer>60</integer> <!-- Run every minute -->

</dict>

</plist>


File permissions (ls -l output): -rwxr-xr-x 1 test staff 512 Feb 17 10:00 /Users/test/Library/LaunchAgents/com.test.logTest.plist

Ran the job with launchctl

I used the following command to load the plist file into launchd:


sudo launchctl bootstrap gui/$(id -u) /Users/test/Library/LaunchAgents/com.test.logTest.plist


pc spec

MacBook Pro

Apple M1

16 GB RAM

macOS 15.3 (Build 24D60)

what I know

The configuration has been set, but the launchd job is not running every minute as expected. I don't believe there is a mistake with the path. When I check the job using launchctl list, the job does not appear in the list. I don't know where the error log files are supposed to be. I checked /var/log/system.log, but there are no error logs. The .sh file runs fine by itself, but it cannot be executed via launchctl.

Want to ask

What could be the cause of the launchd job not running as expected? Also, is there a way to check where the logs are being output? If there is an error in the plist file configuration, which part should be modified? Specifically, what improvements should be made regarding environment variables and path settings?

If my information is not enough, please tell me what is not enough!

Answered by DTS Engineer in 825283022

First up, I recommend that you simplify your tests setup as much as possible. For example, your launchd property list doesn’t need that StartInterval property because, right now, you’re just trying to debug why the job doesn’t start, and you can test that by manually starting it:

% launchctl start com.test.logTest

Note This is using the legacy launchctl commands. Personally I find them easier to understand. I suspect I’m just old (-:

Continuing that process, rather having a script that does stuff, have it simply add an entry to the system log. You can then monitor the log using Console to see if the script runs. I generally use the log command for this:

% log emit --subsystem "com.test.logTest" --category "default" 'First light!'

This lets you specify a subsystem and category, so you can easily find the log entry in the system log. See Your Friend the System Log for more on that.

However, the above is unlikely to actually fix this problem, it’ll just simplify the debugging process. In terms of an actual fix, I noticed that you’ve put your script and all your logging into files nested within folders on the Desktop. I suspect that’s the root cause of this issue, in that such files are restricted by MAC. See On File System Permissions for a definition of that term.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

First up, I recommend that you simplify your tests setup as much as possible. For example, your launchd property list doesn’t need that StartInterval property because, right now, you’re just trying to debug why the job doesn’t start, and you can test that by manually starting it:

% launchctl start com.test.logTest

Note This is using the legacy launchctl commands. Personally I find them easier to understand. I suspect I’m just old (-:

Continuing that process, rather having a script that does stuff, have it simply add an entry to the system log. You can then monitor the log using Console to see if the script runs. I generally use the log command for this:

% log emit --subsystem "com.test.logTest" --category "default" 'First light!'

This lets you specify a subsystem and category, so you can easily find the log entry in the system log. See Your Friend the System Log for more on that.

However, the above is unlikely to actually fix this problem, it’ll just simplify the debugging process. In terms of an actual fix, I noticed that you’ve put your script and all your logging into files nested within folders on the Desktop. I suspect that’s the root cause of this issue, in that such files are restricted by MAC. See On File System Permissions for a definition of that term.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Issue with launchd Job Not Running – "Bootstrap failed: 5: Input/output error"
 
 
Q