热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何在gentooLinux系统上处理crontab事件?-HowtohandlecrontabeventsonagentooLinuxsystem?

IhaveagentooLinuxsystemandastrangebehaviorofcrontab.Asrootuser,andasIunderstandth

I have a gentoo Linux system and a strange behavior of crontab. As root user, and as I understand the documentation, the command

我有一个gentoo Linux系统和crontab的奇怪行为。作为root用户,以及我理解的文档,命令

crontab -l

lists all crontab jobs defined for the current user, root (There are no cronjobs defined for any other used). All listed cronjobs are also defined in the file /etc/cronjob.

列出为当前用户root定义的所有crontab作业(没有为任何其他使用的cronjobs定义)。所有列出的cronjobs也在文件/ etc / cronjob中定义。

However, there are two more crontab files located in /etc/cron.d, which define a cronjob each:

但是,在/etc/cron.d中还有两个crontab文件,它们分别定义了一个cronjob:

/etc/cron.d/testcron1
/etc/cron.d/testcron2

Although not listed with crontab -l, the cronjob defined in the file /etc/cron.d/testcron1 is executed. The other cronjob defined in the file /etc/cron.d/testcron2 is NOT executed.

虽然未与crontab -l一起列出,但执行文件/etc/cron.d/testcron1中定义的cronjob。文件/etc/cron.d/testcron2中定义的另一个cronjob未执行。

This all does not make sense, so I have two questions:

这一切都没有意义,所以我有两个问题:

  • Why does crontab -l list not all cronjobs?
  • 为什么crontab -l列出不是所有的cronjobs?
  • Must the cronjobs in /etc/cron.d be registered somewhere, or is a restart of a daemon/service required? Why is the one started, and not the other one (the executable works fine, though).
  • /etc/cron.d中的cronjobs必须在某处注册,还是需要重新启动守护进程/服务?为什么一个启动,而不是另一个(可执行文件工作正常)。

1 个解决方案

#1


1  

The command crontab is used to maintain/manage crontab files for individual users. These files are usually located in /var/spool/cron/crontabs.

命令crontab用于维护/管理单个用户的crontab文件。这些文件通常位于/ var / spool / cron / crontabs中。

If crontab -l dose not show any cron jobs then this user currently has no individual cron jobs. This dose not mean that there are no cron jobs in /etc/cron* taht will run with the privileges of this user. crontab will not operate on the files in /etc/cron*. It is a tool for only managing individual (per user) cron jobs held in /var/spool/cron/crontabs.

如果crontab -l不显示任何cron作业,则此用户当前没有单独的cron作业。这并不意味着/ etc / cron * taht中没有cron作业将以该用户的权限运行。 crontab不会对/ etc / cron *中的文件进行操作。它是一个仅用于管理/ var / spool / cron / crontabs中保存的个人(每个用户)cron作业的工具。

Now lets see how the different cron jobs get executed. Form the manpage of the cron daemon we can read:

现在让我们看看如何执行不同的cron作业。形成cron守护进程的联机帮助页,我们可以阅读:

cron searches its spool area (/var/spool/cron/crontabs) for crontab files (which are named after accounts in /etc/passwd); ...

cron在其假脱机区域(/ var / spool / cron / crontabs)中搜索crontab文件(以/ etc / passwd中的帐户命名); ...

cron also reads /etc/crontab, which is in a slightly different format (see crontab(5)).

cron还读取/ etc / crontab,它的格式略有不同(参见crontab(5))。

as well as:

以及:

Additionally, in Debian, cron reads the files in the /etc/cron.d directory. cron treats the files in /etc/cron.d as in the same way as the /etc/crontab file...

另外,在Debian中,cron读取/etc/cron.d目录中的文件。 cron以与/ etc / crontab文件相同的方式处理/etc/cron.d中的文件...

(I think this applies to gentoo as well...)

(我认为这也适用于gentoo ...)

About restarting we can read:

关于重启我们可以阅读:

cron then wakes up every minute, examining all stored crontabs, checking each command to see if it should be run in the current minute...

然后cron每分钟醒来,检查所有存储的crontabs,检查每个命令,看它是否应该在当前分钟运行...

Additionally, cron checks each minute to see if its spool directory's modtime (or the modtime on the /etc/crontab file) has changed, and if it has, cron will then examine the modtime on all crontabs files and reload those which have changed. Thus cron need not be restarted whenever a crontab file is modified. Note that the crontab(1) command updates the modtime of the spool directory whenever it changes a crontab.

另外,cron检查每一分钟以查看其假脱机目录的modtime(或/ etc / crontab文件中的modtime)是否已更改,如果有,cron将检查所有crontabs文件的modtime并重新加载已更改的那些。因此,无论何时修改crontab文件,都不需要重新启动cron。请注意,只要crontab(1)命令更改了crontab,它就会更新假脱机目录的modtime。

So the crontab command is for user specific corn jobs while the files in /etc/cron* are more for system cron jobs.

因此,crontab命令用于特定于用户的玉米作业,而/ etc / cron *中的文件则用于系统cron作业。

No manual triggering is needed to activate a new cron job.

激活新的cron作业不需要手动触发。


推荐阅读
  • 启动服务#servicecrondstart或者#etcinit.dcrondstart格式:*  *  *  *  *  command分 时 日 月 周  ... [详细]
  • 一·计划任务1)at1.确定at安装chkconfig–list|grepatd启动at服务:serviceatdrestart2.访问控制如果系统中有etc ... [详细]
  • 想到一个问题,如果在crontab里有个定时任务设置为一分钟执行一次,但是它执行的时间可能会超过一分钟,此时crontab一分钟后会再次运行该脚本吗?这样会不会出现冲突呢?网上找了下,说可以用Linu ... [详细]
  • 前言crontab是Unix和Linux用于设置周期性被执行的指令,是互联网很常用的技术,很多任务都会设置在crontab循环执行,如果不使用crontab,那么任务就是常驻程序,这对你的程序要求比较 ... [详细]
  •   crontab命令用于设置周期性被执行的指令,与windows下的计划任务类似,当安装完成操作系统后,默认会安装此服务工具,并且会自动启动crond进程,crond进程每分钟会定期检查是否有要执 ... [详细]
  • 本文介绍了在RHEL 7中的系统日志管理和网络管理。系统日志管理包括rsyslog和systemd-journal两种日志服务,分别介绍了它们的特点、配置文件和日志查询方式。网络管理主要介绍了使用nmcli命令查看和配置网络接口的方法,包括查看网卡信息、添加、修改和删除配置文件等操作。 ... [详细]
  • 之前项目在windows2003服务器上设置定时任务,每天执行。现在把项目移植到linux系统。也要在linux系统上设置计划任务。但是之前我从来没有做过。所以多得不 ... [详细]
  • 用.sh文件来完成任务,但现在有个项目直接用url就行。一般系统不会有crontabShell#安装crontab:yuminstallcronta ... [详细]
  • Linux下怎么使用crontab命令
    本篇内容主要讲解“Linux下怎么使用crontab命令”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Li ... [详细]
  • 1crond服务未启动crontab不是Linux内核的功能,而是依赖一个crond服务,这个服务可以启动当然也可以停止。如果停止了就无法执行任何定时任务了,解决的方法是打开它 ... [详细]
  • linux 循环 cpu使用率脚本,Linux Shell脚本监视CPU利用率,达到设置的CPU利用率时发送电子邮件...
    有很多开源监控工具可用于监控Linux系统性能,当系统达到给定的阈值限制时,它将发送电子邮件警报。它监视CPU利用率、内存利用率、交换利用率、磁盘空间利 ... [详细]
  • 阿里云mysql性能,阿里云mysql性能
    本文目录一览:1、mysqld占用CPU过高是什么原因 ... [详细]
  • #!binbash########################################################################## File Name : rsync_nobody.sh#  ... [详细]
  • Linux下浅谈crond与crontab的命令用法
    一、什么是crond?crond是Linux系统用来定期执行命令或指定程序的服务的一种服务或软件。一般情况下当我们安装完成Linux操作系统之后,默认便会启动 ... [详细]
  • linux下的crontab默认的最低的是分级别定时器;但是通过sleep睡眠的方式可以实现sleep10;每隔10秒钟定时执行脚本;1.编辑crontab ... [详细]
author-avatar
mce
这个家伙很懒,什么也没留下!
Tags | 热门标签
RankList | 热门文章
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有