0

How do achieve the following cron job into launchd xml format?:

* * * * * date > /Users/mariano/cron_test.log

I've been trying in several ways, but I don't seem to be getting the ProgramArguments right. I guess that the > might be interfering with the xml tags or something.

Any help is greatly appreciated!

5
  • I’m not aware of a converter that ships with Mac, but perhaps this ruby tool can assist in making a correct list to handle the command syntax - github.com/kcrawford/launchd_tools - portion of this.
    – bmike
    Commented Apr 9, 2022 at 21:25
  • For the file handling alone, this might help and the OP there documents some of the time options as a bonus. apple.stackexchange.com/a/217456/5472
    – bmike
    Commented Apr 9, 2022 at 21:27
  • Hello @bmike! And thanks for replying. I have edited my title, sorry for the confusion. I need help translating that cron job on launchd plist format. However, the tool you just posted looks very interesting and quite promising! Thanks! Commented Apr 9, 2022 at 21:27
  • No worries - Editing things here is a super power! There’s so much we don’t know about your skill level, this could go in several directions. launchAgents and Daemons are many times more complicated than cron - so don’t stress if you have several yak shaving moments.
    – bmike
    Commented Apr 9, 2022 at 21:29
  • Thanks again @bmike! Yeah, I can totally see how more complicated it is, haha! But I am trying to learn it as much as I can. My skill level is advanced n00b perhaps? I think that in this case (and thanks to the Ruby tool you provided), seems like the issue is the outputting using the >, that seems to break the program parameters. My aim is to run a launchdaemon that checks a parmeter (for example the date) and outputs results to a log. Maybe I am better off with crontaband not launchd? Hoping you can guide me and thanks again! Commented Apr 9, 2022 at 21:38

1 Answer 1

3

The easiest way to do this is use an App called LaunchControl. It saves having to do the details of a plist. It also can generates the correct StartInterval from a cron time specification. There is also Lingon. Both these are commercial and cost money. LaunchControl also describes what each possible key in the plist does.

In this case the keys that you need are

  • Program - best to use the full path here and also in cron
  • StandardOutPath - to say where the output should go - dealing with your > issue.
  • StartCalendarInterval - to say when it runs

The plist generated by Launch Control is

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>test</string>
    <key>Program</key>
    <string>/bin/date</string>
    <key>StandardErrorPath</key>
    <string>/tmp/test.stderr</string>
    <key>StandardOutPath</key>
    <string>/tmp/cron_test.log</string>
    <key>StartCalendarInterval</key>
    <array>
        <dict/>
    </array>
</dict>
</plist>
2
  • Thank you @mmmmmm! This is what I was looking for. Thanks again! Commented Apr 15, 2022 at 21:30
  • Thanks yet again @mmmmmm! for the tip on how to make it run every minute. I guess I will have to continue reading on Launchd and it's syntax. Commented Apr 16, 2022 at 21:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .