How do I enable crontab on Mac OS x?

Source: Internet
Author: User

project: blogtarget: how-to-enable-crontab-on-osx.mddate: 2015-12-16status: publishtags:    - OS X    - MAC    - crontab    - 定时任务categories:    - OS X    - crontab
Background

Some things on the books are more important, I use Git to manage, so I can back it up to a git repository. But I like to lazy, do not like to always manually perform a series of backup commands, so I thought of writing a backup script, want to crontab to regular backup.
The script was written, and a crontab was added:

# m h  dom mon dow   command30 11,17 * * * /Users/clarence/bin/daily-backup

But why is it not implemented?
Asked the next Niang and Google, the results of many articles are about how to use OS X now comes with the Launchctl to perform scheduled tasks. However, this script is like every morning and afternoon to carry out, with Launchctl to engage in a bit of trouble. So today we have to explore how to enable crontab. The results were found in a few moments and are now shared as follows:

How to enable Crontab

First, since OS X's timing tasks are all managed by LAUNCHCTL, see if the cron task is there:

$  LaunchAgents  sudo launchctl list | grep cron83968   0   com.vix.cron

Sure enough in there. Then check the configuration of this startup item:

$ launchagents Locate com.vix.cron/system/library/launchdaemons/com.vix.cron.plist$ launchagents cat/system/library /launchdaemons/com.vix.cron.plist<?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE plist Public "-//apple computer//dtd plist 1.0//en" "Http://www.apple.com/DTDs/PropertyList-1.0.dtd" >< Plist version= "1.0" ><dict> <key>Label</key> <string>com.vix.cron</string> <ke    y>programarguments</key> <array> <string>/usr/sbin/cron</string> </array> <key>KeepAlive</key> <dict> <key>PathState</key> <dict> & lt;key>/etc/crontab</key> <true/> </dict> </dict> <key>queuedirec tories</key> <array> <string>/usr/lib/cron/tabs</string> </array> <key&gt ; Enabletransactions</key> <true/></dict></pliSt> 

Note that there is a keepalive condition that /etc/crontab exists:

    <key>KeepAlive</key>    <dict>        <key>PathState</key>        <dict>            <key>/etc/crontab</key>            <true/>        </dict>    </dict>

So, let's see if it's because this /etc/crontab doesn't exist that causes the task in cron to not work:

$  LaunchAgents  ll /etc/crontabls: /etc/crontab: No such file or directory

Sure enough, this file does not exist.
Then create it!

$  sudo touch /etc/crontab

Try again if the cron task starts successfully ... Sure enough, it will start successfully!

Knock it off ~

How do I enable crontab on Mac OS x?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.