简体   繁体   中英

Apple Crontab alternative plist to cd a folder and then execute yii script

I want to recreate this crontab to the new apple plist file to describe and execute a background scheduled job.

The reason I want to recreate this is because crontab has depreciate in OSX and i Had a few background process which were working until i made and update to 10.10.3

*/1 * * * * cd /Library/WebServer/Documents/testdrive/protected/ && ./yiic smssender From the crontab i am navigating to protected folder and then executing ./yiic smsSender.

<?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>com.chapskev.crontabtest</string>

        <key>ProgramArguments</key>
        <array>
            <string>/Users/al/bin/crontab-test.sh</string>
        </array>

        <key>Nice</key>
        <integer>1</integer>

        <key>StartInterval</key>
        <integer>60</integer>

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

        <key>StandardErrorPath</key>
        <string>/tmp/AlTest1.err</string>

        <key>StandardOutPath</key>
        <string>/tmp/AlTest1.out</string>
    </dict>
</plist>

Your /Users/al/bin/crontab-test.sh script should contain the commands you want to run:

#!/bin/bash
cd /Library/WebServer/Documents/testdrive/protected/ && ./yiic smssender

Remember to set executable flag for crontab-test.sh :

$ chmod +x crontab-test.sh

Set root as owner of your plist file (the one you posted) and load it as launchd job:

$ sudo chown root crontab.plist
$ sudo launchctl bootstrap system crontab-test.plist

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM