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. 大神是如何玩C语言的!

    我在酷壳上看到一篇文章,C语言结构体里的成员数组和指针,看得感觉让我真是佩服地五体投地啊.皓哥虽说谦称自己不是高手啥的,但是写出这样的文章来,真是让我感觉自己的水平真是渣渣!我看完了感觉有点小激动,也 ...

  2. 使用公司自己的maven服务器时,本地 maven 的配置方法

    使用公司的maven服务器,可以加速jar包的下载. 如果要使用公司的maven服务器,需要对本地maven配置文件conf/settings.xml做相应修改,具体改法有两种.   一.mirror ...

  3. C#函数运行超时则终止执行(任意参数类型及参数个数通用版)

    /// <summary> /// 控制函数执行时间,超时返回null不继续执行 /// 调用方法 /// FuncTimeout.EventNeedRun action = delega ...

  4. centos5.4下mysql主从复制

    centos5.4下mysql主从复制配置分享. 本文转自:http://www.jbxue.com/article/771.html 安装环境:centos 5.4 mysql版本:mysql 5. ...

  5. iOS 点击return或者点击屏幕键盘消失

    //定义两个文本框 UITextField *textName; UITextField *textSummary; //点击return 按钮 去掉 -(BOOL)textFieldShouldRe ...

  6. Linux之父Linus Torvalds:讨厌C++

    "Linux内核的创始人Linus Torvalds最近在一封邮件中说明了内核开发需要使用C语言而非C++的理由.在庞大的项目中,人们对不是自己开发的模块并不了解,能快速理解其他模块中函数的 ...

  7. JAVA读取TXT文本中的数据

    现在在Demo.txt中存在数据: ABC 需要将ABC从文本文件中读取出来 代码片: import java.io.*; class FileReaderDemo { public static v ...

  8. 【python】 入门 搭建环境

    1.去官网下载包 基本程序编译器 python-2.7.10.msi 集成开发环境 pycharm-community-4.5.2.exe 包管理工具 pip-7.0.3.tar.gz 2.安装 按顺 ...

  9. Unity3D实现立体迷宫寻宝

    Unity3D实现立体迷宫寻宝 这个小游戏是一个白痴在一个昏暗的房间走动找到关键得分点,然后通关游戏.入门Unity3D做的第一款游戏,比较无聊,但实现了一般的游戏功能.如,人物控制,碰撞检测,主控制 ...

  10. 【狼窝乀野狼】Serializer妙手回春

    在我们很多程序中,需要将数据保存到本地,以便于下次打开还能看到原始数据.例如我们Xmind思维导图,例如我们的Power Designer等等,都是有保存一个隶属于自己的工程文件,那么今天我要说的就是 ...