I wrote a bash script that backs up certain files on my computer. To automate the running of the script, I set up an associated daemon that runs the script every day.
There are certain instances when I would like the daemon to print error messages. For instance, my script depends on my directory structure and it will run incorrectly if I move certain directories. If the directories on my system do not match those in the script, I would like the daemon to convey an error message so that I can update the script.
Here's the problem: if I were just running the script in the terminal, I could easily have it print an error message to the terminal. But when the daemon runs the script, it does not print anything to the terminal. (Does the daemon print to anything? Where does the printed text go?)
I can see several ways for the daemon to tell the user about an error:
- Use the
wallcommand in the script to print the error to all users
- Use the
launchctl -listcommand to manually check the exit code of the daemon (which the user has to remember to do)
- Hve the script write to some external, user-created error/log file (which the user has to notice/check)
- Use ASL or Syslog (see the Mac Developer Library) to e.g. write the error to an
Option 1 seems too simple. Options 2 and 3 feel unsatisfactory because they only work if the user remembers to check something. I don't know much about Option 4, but it seems built for more complicated types of errors.
What is the recommended way for a daemon to tell the user about an error? (Is this a question for Stack Overflow?)