每隔一周安排一次 LaunchD

每隔一周安排一次 LaunchD

我希望 LaunchD 每隔一周启动一个脚本。以下脚本每周都可以运行,但我如何安排它每隔一周运行一次?

<?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>Program</key>
        <string>/scripts/autoSample</string>
        <key>AbandonProcessGroup</key>
        <true/>
        <key>Debug</key>
        <true/>
        <key>StartCalendarInterval</key>
        <dict>
                <key>Weekday</key>
                <integer>0</integer>
                <key>Minute</key>
                <integer>40</integer>
                <key>Hour</key>
                <integer>8</integer>
        </dict>
        <key>Label</key>
        <string>autoSample</string>
</dict>
</plist>

答案1

那么,使用 2 周(1209600 秒)的 StartInterval 怎么样?

<?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>Program</key>
        <string>/scripts/autoSample</string>
        <key>AbandonProcessGroup</key>
        <true/>
        <key>Debug</key>
        <true/>        
        <key>StartInterval</key>
        <integer>1209600</integer>
        <key>Label</key>
        <string>autoSample</string>
</dict>
</plist>

答案2

您可以在程序开始时添加类似的内容:

(($(date +%V) % 2 == 0)) && exit

相关内容