crontab 是在linux服务器上部署定时任务的方法

0 5 * * * /usr/bin/python /data/www/tools/mysql_backup.py

cmd之前有5个项目要填,分别对应

分钟 小时 天 月 一周当中第几天( 0-6 ,0表示星期天)

填写方法

* 表示都满足,例如 * * * * * 表示每分钟执行一次,如果每小时执行一次,那应该这样写
1 * * * * (每小时第一分钟执行,1可以随便改成60以内的数字)
/n 表示隔n个单位执行一次
/3 * * * * 3分钟执行一次
1 */3 * * * 表示每隔3个小时的第一分钟执行一次
1 1 */3 * * 表示每隔3天,当天的1点1分执行一次
1 12 * * 2,3,4,5,6 表示每周二到周6,每天中午12点1分执行
只需要掌握这2种时间用法,crontab就ok了 提示: crontab 最小粒度是一分钟执行一次,要更快,得用其它办法,比如说写一个daemon程序,用while true: 来做
crontab -l 查看所有crontab 列表
cronta -e 编辑crontab
crontab条目是以文件方式存储的,可以用ls /etc/cron* 查看
标签: linuxcrontab 本文地址: http://lutaf.com/51.htm 鲁塔弗原创文章,欢迎转载,请附带原文链接

  

Create a script you wish to run. For this example, I am going to use the awstats.pl script to update my stats. The command to run the update is: 

/path/to/awstats.pl -update -config=myconfig

2. Create a new crontab file for your user. This is accomplished by opening the Terminal.app, found in your Application/Utilities folder. Type the following into the terminal:

crontab -e

If you do not have a crontab file, one will be created for you and opened in vi.

3. Choose when you would like the job to run. Every job is a line in your crontab file. The first 5 arguments specify the time to run the job, and the 6th argument is the command to run. 

Argument 1: Minute (0 - 59)
Argument 2: Hour (0 - 23)
Argument 3: Day of Month (1 - 31)
Argument 4: Month (1-12)
Argument 5: Day of Week (0 - 6) Sunday = 0
Argument 6: Command So if I want to update my stats every 30 minutes, my entry in my crontab file will look like this: */30 * * * * /path/to/awstats.pl -update -config=myconfig Save the file, and crontab should report: crontab: installing new crontab To see a list of your crontabs, run this command: crontab -l That's it! Crontab will now update the stats every half hour. It also will generate an email to your local user account to let you know it did its job. Most times your local user account's mailbox will not be where you want to be notified. To forward your email, create a file in your home directory called .forward. In the file put the email address where you would like the notification to be sent to.

有的人抱怨说 crontab 无论正确输出还是错误输出都会往 /var/mail/*** 目录下发送邮件 append方式, 不知道别人怎么样,在mac环境下不会出现这种情况,除非 ****** cmd , cmd 有运行错误,就会输入到/var/mail/*** 里面。

mac 下周期调度命令或脚本的更多相关文章

  1. Mac下Shell脚本使用学习笔记(二)

    参考文献 Shell 教程 MAC常用终端命令行 Mac下Shell脚本使用 (7)Shell echo命令: 命令格式:echo string ①显示普通字符串:echo "It is a ...

  2. Mac下Shell脚本使用学习笔记(一)

    参考文献 Shell 教程 MAC常用终端命令行 Mac下Shell脚本使用 1.使用终端创建test.sh: (1)进入指定文件夹路径(命令示例:cd Desktop/面向对象程序设计): (2)创 ...

  3. mac下安装及配置tomcat

    mac下的软件不像windows下的程序那样写注册表,对于tomcat的安装来说,在mac下是名符其实的绿色软件,具体操作如下: 1.到 apache官方主页 下载完整 tar.gz文件包.(没有专门 ...

  4. 2016年最新mac下vscode配置golang开发环境支持debug

    网上目前还找不到完整的mac下golang环境配置支持,本人配置成功,现在整理分享出来. mac最好装下xcode,好像有依赖关系安装Homebrew打开终端窗口, 粘贴脚本执行/usr/bin/ru ...

  5. 【工匠大道】Mac下Java开发环境配置简述

    本文地址 原文地址 分享提纲: 1. 下载JDK1.7 2. 配置java_home 3 .安装tomcat 4 .安装eclipse或者myeclipse 5.  mysql安装 破解版下载请参考M ...

  6. Mac下的类似apt-get的包管理工具Homebrew(笔记)

    对于一个习惯了在 Ubuntu 的终端上通过 apt-get 来安装工具软件的我来说,也希望在Mac上找到类似的工具,能很方便的一条命令就能安装所需的软件,而不用手工的去查找下载编译,或者是折腾安装所 ...

  7. Mac下各种网络命令的使用

    Mac下各种网络命令的使用(http://blog.51yip.com/linux/745.html) pingwww.baidu.com 会一直ping下去,和windows不一样, windows ...

  8. Mac下python初学之Image库(PIL)

    Mac下python 使用Image库 安装PIL,下载http://www.pythonware.com/products/pil/ 解压PIL源码包,阅读README知道需要使用python se ...

  9. Mac下安装 PIL

     最近入手MacBook Pro 在配置PIL环境的时候遇到一些问题.现在把解决方式记录下来,希望对有需要的有所帮助. 1. 安装brew : brew 又叫Homebrew,是Mac OSX上的软件 ...

随机推荐

  1. 基于BT协议的文件分发系统

    基于BT协议的文件分发系统构成:    1.一个Web服务器:保存着种子文件    2.一个种子文件:保存共享文件的一些信息(文件名,文件大小    ,Tracker服务器地址,torrent为后缀) ...

  2. c# 分页控件

    因为最近做的培训项目需要用到很多分页功能,自己写了一个分页方法,想找个时间重构,看到一篇博客,转载过来,分享学习. 原文链接:http://www.cnblogs.com/rr163/p/395593 ...

  3. string和stringBuilder的区别

    曾经被问到过这个问题,回答得不是很好,在网上找了一下,园子里有大神很详细地讨论了二者的区别. http://www.cnblogs.com/yunfeng8967/articles/1093832.h ...

  4. javascript和jquery 获取触发事件的元素

    一个很简单的问题,却因为大意,经常忘了处理,导致程序运行出错. <!DOCTYPE html> <html> <head> <meta charset=&qu ...

  5. SQLdiag Utility

    使用SQLdiag 会进行信息搜集类型 Windows 系统性能日志 Windows 系统日志 SQL Server 性能信息 SQL Server 阻塞信息 SQL Server 配置信息 如何使用 ...

  6. Linux使用标准IO的调用函数,分3种形式实现

    /*根据cp命令的格式要求,设计一个类cp的功能程序,要求使用标准IO的调用函数,分3种形式实现,字符,行,块.并注意函数功能的分层*/ #include<stdio.h> #includ ...

  7. PropertyDrawer 自定义属性绘图

    public class PlayerAttributeExample : MonoBehaviour { //无滑块的属性 ; //特性限定,有滑块 [Range(, )] ; } Range特性的 ...

  8. matlab实现高斯消去法、LU分解

    朴素高斯消去法: function x = GauElim(n, A, b) if nargin < 2 for i = 1 : 1 : n for j = 1 : 1 : n A(i, j) ...

  9. 《Dive into Python》Chapter 2 and Chapter 3 笔记

    Example 2.1. odbchelper.py def buildConnectionString(params): """Build a connection s ...

  10. java 非法字符过滤 , 半角/全角替换

    java 非法字符过滤 , 半角/全角替换 package mjorcen.netty.test1; import java.io.UnsupportedEncodingException; publ ...