crontab

How do set cron to run my script every 40mins/25mins?

自作多情 提交于 2019-11-29 03:23:07
I want a script to run every 40mins beginning on the 40th minute. so that means: 00:40, 01:20, 02:00, 02:40, 03:20... So I made this entry to cron: */40 * * * * /path/to/script/foo.sh Unfortunately this runs the script every 40th minute of the hour: 00:40, 01:40, 02:40... The same goes with the script that I meant to run every 25mins. Am I missing something here? ANSWERS Alright, in case you happen to drop by here having the same problem here's how I solved it: # 40mins-interval 40 0 * * * /path/foo.sh (0) 0,40 2-22/2 * * * /path/foo.sh (2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22) 20 1-23/2 * * *

linux之安排周期性任务

夙愿已清 提交于 2019-11-29 03:16:16
每个用户都可以设置自己的crontab文件,以便执行用户自己需要的自动运行的任务。用户自己的crontab文件位于/var/spool/cron/目录,但用户不能直接编译这些文件,用户必须使用crontab命令来编辑它。 crontab命令用于安装,删除或者列出用于驱动cron后台进程的crontab任务。 自动安排用户的进程任务举例 //1.执行如下命令安排root用户的crontab任务 crontab -e //2.在vi中编写crontab任务,添加如下行,每月1日和15日凌晨1:30使系统进行维护状态,重新启动系统 30 1,15 * * shutdown -r +10>/dev/null 2>&1 //3.每天凌晨的2点删除/ftp/incoming/temp目录下的所有文件 00 02 * * * rm -rf /ftp/incoming/temp //4.每天凌晨1点删除/tmp目录下的7天没有修改过的所有子目录,不包括/tmp当前目录和lost+found目录 00 01 * * * find /tmp ! -name .! -name lost+found \ -type d -mtime +7 -exec /bin/rm -rf {} ';' //5.每天早上8点将/var/log/secure文件内容发送给aa@163.com 0 8 * * * mail

进程管理

末鹿安然 提交于 2019-11-29 02:19:28
一、进程的概念与分类 进程的的基本定义是 :在自身的虚拟地址空间运行的一个独立的程序,从操作系统的角度来看,所有在系统上运行的东西,都可以称为一个进程。 进程的分类:  系统进程: 可以执行内存资源分配和进程切换等管理工作;而且,该进程的运行不受用户的干预,即使是root用户也不能干预系统进程的运行。  用户进程: 通过执行用户程序、应用程序或内核之外的系统程序而产生的进程,此类进程可以在用户的控制下运行或关闭。 交互进程: 由一个shell终端启动的进程,在执行过程中,需要与用户进行交互操作,可以运行于前台,也可以运行在后台。 批处理进程: 该进程是一个进程集合,负责按顺序启动其他的进程。 守护进程: 守护进程是一直运行的一种进程,经常在linux系统启动时启动,在系统关闭时终止。例如httpd进程,一直处于运行状态,等待用户的访问。还有经常用的crond进程,这个进程类似与windows的计划任务,可以周期性的执行用户设定的某些任务。 二、进程的监控与管理 在linux系统中,进程ID(用PID表示)是区分不同进程的唯一标识,它们的大小是有限制的,最大ID为32768,用UID和GID分别表示启动这个进程的用户和用户组。所有的进程都是PID为1的init进程(centos7.x版本是systemd进程)的后代。内核在系统启动的最后阶段启动init进程,因而

Run every 2nd and 4th Saturday of the month

一曲冷凌霜 提交于 2019-11-29 02:01:17
What's the cron (linux) syntax to have a job run on the 2nd and 4th Saturday of the month? The second Saturday of the month falls on one (and only one) of the dates from the 8 th to the 14 th inclusive. Likewise, the fourth Saturday falls on one date between the 22 nd and the 28 th inclusive. You may think that you could use the day of week field to limit it to Saturdays (the 6 in the line below): 0 1 8-14,22-28 * 6 /path/to/myscript Unfortunately, the day-of-month and day-of-week is an OR proposition where either will cause the job to run, as per the manpage: Commands are executed by cron

crontab run every 15 minutes between certain hours

余生颓废 提交于 2019-11-29 01:48:26
问题 Is this correct scheduled to run between 07:00 and 19:00 at every 15 minutes? */15 07-19 * * * /path/script 回答1: Yes! Well, more or less This will run from 7.00 until 19.45, every 15 minutes: */15 07-19 * * * /path/script If you want it to run until 19.00 then you have to write two lines: */15 07-18 * * * /path/script 0 19 * * * /path/script You can have a full description of the command in crontab.guru: https://crontab.guru/#/15_7-19___ 回答2: Yes, that's correct. The entry in crontab would

How to run Cronjobs more often than once per minute?

喜欢而已 提交于 2019-11-29 01:42:49
I created a Email-Queue database table. I will insert all Emails my PHP application needs to send into this table. Another PHP script will then look for all unsent Emails and sends them. I run this script using cronjobs. Unfortunately cronjobs can run only at a maximum of once per minute. So in the worst-case a user has to wait one minute until his Email is really going to be sent. My current idea for a workaround is calling the script with an addtional sleep parameter and duplicating the cronjobs. Example: * * * * * curl emails.php?sleep=0 >/dev/null 2>&1 * * * * * curl emails.php?sleep=10 >

Redirecting the output of a cron job

a 夏天 提交于 2019-11-29 01:10:20
问题 I have the following entry in crontab: 0 5 * * * /bin/bash -l -c 'export RAILS_ENV=my_env; cd /my_folder; ./script/my_script.rb 2>&1 > ./log/my_log.log' The result of this is that I am receiving the output of ./script/my_script.rb in ./log/my_log.log . This behavior is desired. What is curious is that I am also receiving the output in my local mail. I am wondering how the output of my script is being captured by mail. Since I am redirecting the output to a log file, I would expect that my

Linux之crontab定时任务篇

自古美人都是妖i 提交于 2019-11-28 21:49:53
为当前用户创建cron服务 键入 crontab -e 编辑crontab服务文件 例如新增一行脚本 30 21 * * * /app/iarBatch/xshell/batch/start_Alarm_PoliceFace.sh 查看该用户下的crontab服务是否创建成功, 用 crontab -l 命令 启动crontab服务 一般启动服务用 /sbin/service crond start 若是根用户的cron服务可以用 sudo service crond start 查看服务是否已经运行用 ps -ax | grep cron crontab命令 cron服务提供crontab命令来设定cron服务的,以下是这个命令的一些参数与说明: crontab -u //设定某个用户的cron服务,一般root用户在执行这个命令的时候需要此参数   crontab -l //列出某个用户cron服务的详细内容   crontab -r //删除没个用户的cron服务   crontab -e //编辑某个用户的cron服务   比如说root查看自己的cron设置:crontab -u root -l   再例如,root想删除fred的cron设置:crontab -u fred -r   在编辑cron服务时,编辑的内容有一些格式和约定,输入:crontab -u root

Parsing crontab-style lines

微笑、不失礼 提交于 2019-11-28 21:14:52
问题 I need to parse a crontab-like schedule definition in Python (e.g. 00 3 * * *) and get where this should have last run. Is there a good (preferably small) library that parses these strings and translates them to dates? 回答1: Perhaps the python package croniter suits your needs. Usage example: >>> import croniter >>> import datetime >>> now = datetime.datetime.now() >>> cron = croniter.croniter('45 17 */2 * *', now) >>> cron.get_next(datetime.datetime) datetime.datetime(2011, 9, 14, 17, 45) >>>

Using crontab with django [duplicate]

大兔子大兔子 提交于 2019-11-28 20:49:36
This question already has an answer here: Django - Set Up A Scheduled Job? 23 answers I need to create a function for sending newsletters everyday from crontab. I've found two ways of doing this on the internet : First - file placed in the django project folder: #! /usr/bin/env python import sys import os from django.core.management import setup_environ import settings setup_environ(settings) from django.core.mail import send_mail from project.newsletter.models import Newsletter, Address def main(argv=None): if argv is None: argv = sys.argv newsletters = Newsletter.objects.filter(sent=False)