Como os arquivos em /etc/cron.d são usados?

4

Como os arquivos em /etc/cron.d são usados?

De link

cron reads the files in /etc/cron.d/ directory. Usually system daemon such as sa-update or sysstat places their cronjob here. As a root user or superuser you can use following directories to configure cron jobs. You can directly drop your scripts here. The run-parts command run scripts or programs in a directory via /etc/crontab file:

/etc/cron.d/ Put all scripts here and call them from /etc/crontab file.

No Lubuntu 18.04, os arquivos em /etc/cron.d parecem ser arquivos crontab e não shell scripts (que foram mencionados no link acima):

$ cat /etc/cron.d/anacron 
# /etc/cron.d/anacron: crontab entries for the anacron package

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

30 7    * * *   root    [ -x /etc/init.d/anacron ] && if [ ! -d /run/systemd/system ]; then /usr/sbin/invoke-rc.d anacron start >/dev/null; fi

Meu arquivo / etc / crontab nunca se refere a arquivos em / etc / cron.d, ao contrário do que diz o link:

$ cat /etc/crontab 
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the 'crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )

Você poderia explicar como os arquivos em /etc/cron.d são usados? Obrigado.

    
por Tim 27.07.2018 / 01:36

1 resposta

7

Nos derivados do Debian, incluindo Lubuntu, os arquivos em /etc/cron.d são efetivamente /etc/crontab snippets, com o mesmo formato. Citando a cron manpage :

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 (they follow the special format of that file, i.e. they include the user field). However, they are independent of /etc/crontab: they do not, for example, inherit environment variable settings from it. This change is specific to Debian see the note under DEBIAN SPECIFIC below.

Like /etc/crontab, the files in the /etc/cron.d directory are monitored for changes. In general, the system administrator should not use /etc/cron.d/, but use the standard system crontab /etc/crontab.

A seção específica do Debian sugere o motivo pelo qual os administradores do sistema não devem usar /etc/cron.d :

Support for /etc/cron.d (drop-in dir for package crontabs)

Ele foi projetado para permitir que os pacotes instalem trechos do crontab sem ter que modificar /etc/crontab .

    
por 27.07.2018 / 01:51

Tags