crontab

Unix crontab命令 添加定时任务

ε祈祈猫儿з 提交于 2019-12-03 12:24:01
Unix crontab命令 添加定时任务 使用crontab命令要求root身份 1. crontab -1 [username] 列出用户现有任务的列表 RH Linux 为 crontab -u username -l 列出指定用户现有任务的列表 2. crontab -d [username] 删除用户目前的任务 3. crontab-c dir- 指定crontab的目录 4. 如果想添加一个任务或想编辑任务 使用 crontab -e 命令,进入一个VI的编辑界面,既可以添加或修改任务了 时间说明 *  *  *  *  *  command 分 时 日 月 周 命令 第1列表示分钟1~59 每分钟用*或者 */1表示 第2列表示小时1~23(0表示0点) 第3列表示日期1~31 第4列表示月份1~12 第5列标识号星期0~6(0表示星期天) 时间部分 * 逗号(',') 指定列表值。如: "1,3,4,7,8" * 中横线('-') 指定范围值 如 "1-6", 代表 "1,2,3,4,5,6" * 星号 ('*') 代表所有可能的值 第6列要运行的命令: 文件路径 参数 例子 : 30 21 * * * /etc/ restart 常见陷阱 每个SA、DBA 或者是普通的 Unix 用户,在第一次使用 Crontab 的时候都会遇到问题. 运行 Crontab

crontab系统使用雷区(为什么cron任务没运行)

試著忘記壹切 提交于 2019-12-03 12:23:44
1. 写好的程序,手动执行没问题,上crontab就报错 Crontab任务的执行环境与手动执行时的执行环境不同。 手动执行时,任务的执行环境为当前用户或指定用户的执行环境,典型的执行环境是环境变量,此时环境变量可以用env查看。Crontab调度时,执行环境的环境变量大为缩减,如下为用root用户执行crontab任务时的环境变量 SHELL=/bin/sh USER=root PATH=/usr/bin:/bin PWD=/root SHLVL=1 HOME=/root LOGNAME=root _=/usr/bin/env 所以,编码时,尽量通过全路径名引用文件或调用命令,或者将引用的文件或者命令的路径添加到环境变量中,或者脚本开始处切换一下当前目录 2. Crontab任务的输出重定向文件无写权限 通常情况下,在添加crontab任务之前,都会手动执行一下待添加的crontab任务,此时,通过重定向产生的文件,只执行该任务的用户有写权限,由sudo -u指定的用户并没有写权限。本质原因是sudo –u对重定向符不起作用。如此,在添加crontab任务,以sudo –u中指定的用户身份运行时,由于对重定向文件无写权限,crontab任务会安静的失败 3. Crontab任务配置文件owner不是root 在添加crontab任务时,如果配置文件owner不是root

crontab 使用

醉酒当歌 提交于 2019-12-03 09:36:44
1. 安装,结构 yum install cronie 结构: * * * * * [分钟] [小时] [每月的某一天] [每年的某一月] [每周的某一天] 2.命令 1,添加或更新crontab中的命令 crontab -e 进入编辑状态: # */1 * * * * /usr/local/taoyongtao/mysql_dump/mysql_auto_dump.sh > /usr/local/taoyongtao/mysql_dump/test.log */2 * * * * /qqc/test.py >> /qqc/te.log 2>&1 2. 查看当前系统登录用户的Crontab命令集合 [root@localhost qqc]# crontab -l # */1 * * * * /usr/local/taoyongtao/mysql_dump/mysql_auto_dump.sh > /usr/local/taoyongtao/mysql_dump/test.log */2 * * * * /qqc/test.py >> /qqc/te.log 2>&1 3,查看其他用户的Crontab命令集合 crontab -u username -l 注:查看用户[root@localhost qqc]# cat /etc/passwd 4,日志记录 [root

迷惑性很强的crontab

泪湿孤枕 提交于 2019-12-03 09:33:23
提到定时任务,我们通常会想起linux的 crontab ,可以说服务器端大部分定时任务都是由它完成的。这东西固然耗用,但是坑也不少。 这不,昨天我在部署一个备份任务的时候,就不幸踩坑了。差点酿成大祸。 首先,介绍一下crontab的特点: 此命令为系统自带命令,可通过crontab + 选项直接调用。相当于修改/var/spool/cron/usename文件。 常用选项如下: 选项 含义 -e 编辑该用户下的crontab配置 -r 删除该用户下的crontab配置 -l 浏览该用户下的crontab配置 此命令非特权命令,任何用户可以调用。如下: [root@master cron]# whereis crontab crontab: /usr/bin/crontab /etc/crontab /usr/share/man/man1/crontab.1.gz /usr/share/man/man1p/crontab.1p.gz /usr/share/man/man5/crontab.5.gz 此命令有服务,可以通过crond来启动、停止、查看状态。 其次,介绍一下crontab的用法: crontab包含六个参数,前五个是指定时间的,最后一个是命令参数,指定执行什么命令或脚本。 前五个参数分别是: 分: 取值0-59,*代表每分钟执行一次 时: 取值0-23,

Crontab executes only first line

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to setup several cron jobs on VPS under centos/whm. I've added to /var/spool/cron/root following lines: */5 * * * * find /some-dir/* \( ! -iname ".ht*" \) -delete */10 * * * * find /some-other-dir/* \( ! -iname ".ht*" \) -delete but only the first line executed ( for /some-dir/). If I swap lines - /some-other-dir/ executed, /some-dir/ - not. I've tried to put semicolons at the end of each line, to put spaces, tabs, change file encoding - nothing. How can I make cron process both tasks? here is the /var/log/cron output: Sep 18 11

Setting Cron job to delete file after 24 hours

爱⌒轻易说出口 提交于 2019-12-03 08:34:12
I read all the related questions and was unable to understand them. I am using Plesk CPanel to set cron job as it was advised by everyone. I want to delete all files from a folder after 24 hours. Assume that I have to delete it after every 2 mins (So I can check its working or not). I have two options: Either run a PHP file that deletes all files after 24 hours using a cron job Use the cron job command `rm` to delete all the files I tried both ways and was unable to get my task completed. Here is the pic of cpanel scheduled task: http://i41.tinypic.com/2n0tsfs.png I want to delete files from

Cron job run every x weeks and on specific days [closed]

点点圈 提交于 2019-12-03 08:10:57
Closed. This question is off-topic. It is not currently accepting answers. Learn more . Want to improve this question? Update the question so it's on-topic for Stack Overflow. I want to create a cron job that runs every x weeks and on a specific weekdays. for example: run every 2 weeks on midnight every Sunday and Monday. the cron expression is stored for every "plan" and i use ncrontab function in SQL Server 2008 to generate the dates of given cron expression. Is there an expression for it? or even join of several expressions? I've tried to use the following expression, but it always gives

Cron and Crontab files not executed in Docker

孤者浪人 提交于 2019-12-03 07:31:32
I have this simple Dockerfile for testing, but this is also same in my LEMP stack in a PHP image: cron jobs simply not being executed in Docker. This is my testing Dockerfile: FROM debian:latest MAINTAINER XY <info@domain.com> LABEL Description="Cron" Vendor="Istvan Lantos" Version="1.0" RUN apt-get -y update && apt-get -y dist-upgrade \ && apt-get -y install \ cron \ rsyslog \ vim RUN rm -rf /var/lib/apt/lists/* #cron fixes RUN touch /etc/crontab /etc/cron.d/* /var/spool/cron/crontabs/* #COPY etc/cron.d /etc/cron.d COPY etc/crontab /etc/crontab #COPY var/spool/cron/crontabs /var/spool/cron

tp5定时任务

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 07:13:05
第一步: a.App/模块/ 下创建command文件夹 b.我这边是创建在crontab模块里面,在command文件夹下创建一个Task.php文件(具体名字自己根据需求定) c.复制下面的代码到Task.php <?php namespace app\crontab\command; use think\console\Command; use think\console\Input; use think\console\input\Argument; use think\console\input\Option; use think\console\Output; use think\Db; class Task extends Command { protected function configure() { $this->setName('task') ->setDescription('定时计划测试:每分钟插入一条数据'); } protected function execute(Input $input, Output $output) { // 输出到日志文件 $output->writeln("TestCommand:"); // 定时器需要执行的内容 $data = [ 'name'=>'zxm22', 'addr'=>'上海' ]; db('blog')

How do you deploy cron jobs to production?

廉价感情. 提交于 2019-12-03 05:45:42
问题 How do people deploy/version control cronjobs to production? I'm more curious about conventions/standards people use than any particular solution, but I happen to be using git for revision control, and the cronjob is running a python/django script. 回答1: If you are using Fabric for deploment you could add a function that edits your crontab. def add_cronjob(): run('crontab -l > /tmp/crondump') run('echo "@daily /path/to/dostuff.sh 2> /dev/null" >> /tmp/crondump') run('crontab /tmp/crondump')