Getting started with cronjobs on a Mac

前端 未结 6 2075
失恋的感觉
失恋的感觉 2021-01-01 01:40

I\'m trying to get familiar with cron jobs, and I think I get the basic idea (scheduling, syntax, etc), But, I can\'t seem to get it right on my mac with Terminal - where ex

6条回答
  •  感动是毒
    2021-01-01 02:08

    To get started with launchd (instead of cron) you'll want to first create an empty .plist file, for example local.mytask.plist and put it somewhere. ~/Library/LaunchAgents is probably a good place. Open that in text editor and copy in the code below

    
    
    
    
    KeepAlive
    
    Label
    local.mytask
    ProgramArguments
    
    /opt/local/bin/wget
    http://someserver/somepage.php
    
    StartInterval
    300
    RunAtLoad
    
    StandardErrorPath
    /dev/null
    StandardOutPath
    /dev/null
    
    
    

    Then "activate" the file from the command line:

    sudo launchctl load /Users/my_username/Library/LaunchAgents/local.mytask.plist
    

    To make it load automatically, create a ~/.launchd.conf file with the same line (minus sudo launch)

    load /Users/my_username/Library/LaunchAgents/local.mytask.plist
    

    The above instructions above have been copied from www.davidlanier.com and reposted here for your reference.

提交回复
热议问题