Use Crontab to implement timed tasks under Mac

Source: Internet
Author: User

Description

1, Linux and Mac operating crontab are consistent

2, the configuration files are under/etc/crontab, if not created.

3. The test finds that the scheduled task created directly with the CRONTAB-E command is placed in the Temp folder, and the restart is deleted and is not associated with the/etc/crontab file.

Actual operation:

    • See if Crontab is started

      sudo grep Cron
    • Check for required files

      $  launchagents  ll/etc/crontablsfile or directory  #表示没有这个文件, you need to create a
    • Create a file

      sudo Touch

Parameters of the Crontab

    • -u User: Used to set a user's crontab service;file: File is the name of the command, which indicates that file is thecrontab task list and loaded into crontab. If this file is not specified on the command line, the crontab command will accept the commands typed on the standard input (keyboard) and load them into crontab. -E: Edit the contents of a user's crontab file. If you do not specify a user, the crontab file for the current user is edited. -L: Displays the contents of a user's crontab file, or displays the contents of the current user's crontab file if no user is specified. -R:Deletes a user's crontab file from the/var/spool/cron directory and, if no user is specified, deletes the current user's crontab file by default. -I: Give a confirmation prompt when deleting a user's crontab file.

Eg: */1 * * * * /bin/date >> /User/Username(你的用户名)/time.txt indicates the output of the current time to Time.txt per minute.

    • If the following issues occur

       for Hayek-"/usr/bin/vi"1
      1. Method 1: EDITOR=vim crontab -e edit directly, directly after the direct crontab -e opening on the line.
      2. Method 2:export EDITOR=vim
      3. Method 3: Before submitting a crontab file to the cron process, first set the environment variable editor. The cron process depends on it to determine which editor to use to edit the crontab file. 9 9 of UNIX and Linux users use VI, and if you do, then you edit the $home directory. Profile file in which to add such a line:
        EDITOR=vi; export EDITOR

File formats for crontab

    * 第1列分钟0~59    * 第2列小时0~23(0表示子夜)    * 第3列日1~31    * 第4列月1~12    * 第5列星期0~7(0和7表示星期天)    * 第6列要运行的命令

Crontab Service restart shutdown, open

    • Under Mac System

      sudo /usr/sbin/cron startsudo /usr/sbin/cron restartsudo /usr/sbin/ Cron Stop
    • Ubuntu:

      sudo /etc/init.d/cron startsudo /etc/init.d/cron stopsudo /etc/ Init.d/cron restart

Reference:

http://blog.csdn.net/zhenhanhong_tony/article/details/52658055

http://blog.csdn.net/zmzwll1314/article/details/52389967

http://blog.csdn.net/biyongyao/article/details/77791238 (the above content is transferred from this article)

http://blog.csdn.net/meixuesong/article/details/27481883

http://blog.csdn.net/lgt633744/article/details/45932035 (Alternative timing task implementation)

Use Crontab to implement timed tasks under Mac

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.