crontab

deleting old files using crontab

五迷三道 提交于 2019-12-17 18:56:10
问题 I use the following crontab record in order to daily backup my DB: 0 2 * * * MYSQL_PWD=password mysqldump -u user db_name > $HOME/db_backups/db_name-$(date +\%Y-\%m-\%d-\%H-\%M).sql 2>> $HOME/db_backups/cron.log I want to add another crontab record that will delete the DB dumps that are older then one month. Any thoughts? 回答1: Just create another cron: 0 3 * * * find $HOME/db_backups -name "db_name*.sql" -mtime +30 -exec rm {} \; >> $HOME/db_backups/purge.log 2>&1 It will find all backups

Significance of question mark in Java cron

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-17 17:59:42
问题 Source Wikipedia: Question mark (?) is used instead of '*' for leaving either day-of-month or day-of-week blank. The above statement is not making much sense to me. So if I write some cron as 0 0 0 ? * * then does it mean first of every month or it means it will execute daily? It is a bit confusing as Java crons start with seconds while other crons start with minute. 回答1: According to the Quartz CronTrigger tutorial (Quartz is used by www.cronmaker.com, referenced above), the ? wildcard is

linux定时执行shell脚本

こ雲淡風輕ζ 提交于 2019-12-17 16:44:44
在oracle 中可以利用dbms_job包定时执行pl/sql、sql过程,在像备份等需要在操作系统级定时任务只能采用crontab来完成。 利用crontab来定时执行任务大致有如下三步: 1、编写shell脚本 2、利用crontab加入到定时任务队列 3、查看作业完成情况 一、如何建立shell脚本 Linux下有很多不同的shell,但我们通常使用bash(bourne again shell)进行编程,因为bash是免费的并且很容易使用 程序必须以下面的行开始(必须方在文件的第一行): #! /bin/sh 符号#!用来告诉系统它后面的参数是用来执行该文件的程序。在这个例子中我们使用/bin/sh来执行程序。 当编辑好脚本时,要想执行脚本,必须使脚本可以执行 下面的命令,可以使脚本可以执行 chmod +x filename 然后可以输入./filename来执行脚本。 注:在shell编程时,#符号表示注释,只该行结束为止。在编写程序时,最好使用注释。 变量 shell下所有变量都以字符串表示,变量不需要声明,直接使用。直接对变量进行赋值 A="hello world" 取出变量用$符号,如: #! /bin/sh A="hello world" echo "A is:" echo $A 执行该脚本输出结果如下: A is : hello world shell

How to run crontab job every week on Sunday

≯℡__Kan透↙ 提交于 2019-12-17 14:59:08
问题 I'm trying to figure out how to run a crontab job every week on Sunday. I think the following should work, but I'm not sure if I understand correctly. Is the following correct? 5 8 * * 6 回答1: Here is an explanation of the crontab format. # 1. Entry: Minute when the process will be started [0-60] # 2. Entry: Hour when the process will be started [0-23] # 3. Entry: Day of the month when the process will be started [1-28/29/30/31] # 4. Entry: Month of the year when the process will be started [1

Crontab Formatting - every 15 minutes

女生的网名这么多〃 提交于 2019-12-17 10:58:19
问题 I'm trying to get a simple crontab job to run every 15 minutes and am having trouble deciding how to format the timing. What I've been putting down is the following: 15 * * * * ------------------------ I'm pretty sure this just runs the first 15 minutes of every hour. I think that crontab allows users to specify exact times to run, namely: 0, 15,30,45 * * * * ------------------------- But if I wanted to run the crontab every 15 minutes from the moment I start it, (which may not necessarily be

django中使用celery

蹲街弑〆低调 提交于 2019-12-17 10:30:04
目录 一.引言 二.Celery,Django和Djcelery 三. Django目录结构 四. 配置setting.py 1.加入djcelery 2. 设置celery参数 5.Tasks任务 6.启动定时任务 7.推荐文章 一.引言 Django是python语言下的一个比较热门的Web框架,越来越多的企业和开发者使用Django实现自己的Web服务器。在Web服务器开发过程中,有时候我们不仅仅是要实现Web服务器端和用户端的简单逻辑交互,还要实现一些定时任务。举出以下的例子:   定期删除或缓存Redis数据库的记录 为了追求更高的数据库访问性能,我把Redis作为MySql数据库的缓存。把常访问的数据放在Redis中,然后定时存储到Mysql中。并且把过期的Redis数据删掉.那么这个时候,就需要定时去完成这个任务。 生成报表    打个比方,你有一个Web电商服务器,每天用户都在会在上面购物。为了很方便的统计出每个用户每个月的消费金额,你在数据库中设计了一张月统计报表。然后使用定时任务,在每个月的1号进行统计,检索数据库,计算出每个用户上个月的的消费金额,逐个存储到月统计报表中。那么这个生成报表的任务就是定时完成的,也就是前面提到的每个月的1号。 定时发送消息 再如:当你的网站上用户生日来临,你希望在他生日那天,给用户的邮箱发送生日快乐的祝福。那么这也是定时任务实现的

Executing php with crontab

北城余情 提交于 2019-12-17 05:05:26
问题 I'm trying to run a php-script on a scheduled basis. So I'd thought crontab was a good idea. The server I'm using is on Linux which I'm not that familiar with. So the problem I'm having is, I don't know how make the script executable from php. I need to reference the script, or put it into a folder that can run php from the command line. So I don't know what path to give my crontab, for example: 5 * * * * var/www/some/path/script.php I found some vague information about this php executable

Why is crontab not executing my PHP script?

北城以北 提交于 2019-12-17 04:02:12
问题 I have built one php file to check some result, so that I need to setup a cronjob. I set one to run every 30 minute, so that the results will be send. However, I don't know why my crontab did not run after every 30 minute. Here is how I set the crontab: */30 * * * * php /var/www/html/result.php I have confirmed my file directory is correct. What I not sure is about the timing part: isn't it possible to use */30 * * * * or 30 * * * * ? I set */30 * * * * and did not work. 回答1: Given */30 * * *

Crontab的格式

て烟熏妆下的殇ゞ 提交于 2019-12-16 23:55:26
第1列分钟1~59 第2列小时1~23(0表示子夜) 第3列日1~31 第4列月1~12 第5列星期0~6(0表示星期天) 第6列要运行的命令 下面是crontab的格式: 分 时 日 月 星期 要运行的命令 这里有crontab文件条目的一些例子: 30 21 * * * /usr/local/apache/bin/apachectl restart 上面的例子表示每晚的21:30重启apache。 45 4 1,10,22 * * /usr/local/apache/bin/apachectl restart 上面的例子表示每月1、10、22日的4 : 45重启apache。 10 1 * * 6,0 /usr/local/apache/bin/apachectl restart 上面的例子表示每周六、周日的1 : 10重启apache。 0,30 18-23 * * * /usr/local/apache/bin/apachectl restart 上面的例子表示在每天18 : 00至23 : 00之间每隔30分钟重启apache。 0 23 * * 6 /usr/local/apache/bin/apachectl restart 上面的例子表示每星期六的11 : 00 pm重启apache。 * */1 * * * /usr/local/apache/bin

定时任务crontab

偶尔善良 提交于 2019-12-16 15:05:12
crontab:定时任务的守护进程,精确到分,设计秒的我们一般写脚本 -->相当于闹钟 日志文件: ll /var/log/cron* 编辑文件: vim /etc/crontab 进程:ps -ef | grep crond ==> /etc/init.d/crond restart 作用:定时备份,实时备份 常见命令参数 1 2 3 4 5 6 7 8 usage: crontab [-u user] file crontab [-u user] [ -e | -l | -r ] (default operation is replace, per 1003.2) -e (edit user's crontab ) -l (list user's crontab ) -r (delete user's crontab ) -i (prompt before deleting user's crontab ) -s (selinux context) 定时任务分类 Linux下的任务调度分为两类,系统任务调度和用户任务调度。 系统任务调度:系统周期性所要执行的工作,比如写缓存数据到硬盘、日志清理等。 在/etc/crontab文件,这个就是系统任务调度的配置文件。 用户任务调度:用户定期要执行的工作,比如用户数据备份、定时邮件提醒等。 用户可以使用 crontab