/etc/cron.d 아래의 파일을 어떻게 사용합니까?

/etc/cron.d 아래의 파일을 어떻게 사용합니까?

/etc/cron.d 아래의 파일을 어떻게 사용합니까?

~에서 https://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/

cron은 /etc/cron.d/ 디렉터리의 파일을 읽습니다.일반적으로 시스템 데몬(예: sa-update 또는 sysstat)은 cronjob을 여기에 배치합니다. 루트 또는 수퍼유저로서 다음 디렉터리를 사용하여 cron 작업을 구성할 수 있습니다. 여기에 직접 스크립트를 끌어다 놓을 수 있습니다..run-parts 명령은 /etc/crontab 파일을 통해 디렉토리에 있는 스크립트나 프로그램을 실행합니다.:

/etc/cron.d/ 모든 스크립트를 여기에 배치하고 /etc/crontab 파일에서 호출합니다.

Lubuntu 18.04에서 /etc/cron.d 아래의 파일은 쉘 스크립트가 아닌 crontab 파일로 나타납니다(위 링크에서 언급됨).

$ 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

내 /etc/crontab 파일은 링크 내용과 달리 /etc/cron.d 아래의 파일을 참조하지 않습니다.

$ 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 )

/etc/cron.d 아래의 파일이 어떻게 사용되는지 설명해 주실 수 있나요? 감사해요.

답변1

Debian 파생물(Lubuntu 포함)에서 파일은 /etc/cron.d실제로 /etc/crontab조각이며 동일한 형식을 갖습니다. 인용하다cron맨페이지:

또한 데비안에서는 cron디렉터리의 파일을 읽습니다 /etc/cron.d. 파일은 파일과 동일한 방식으로 처리됩니다 cron(해당 파일의 특수 형식을 따릅니다. 즉, 사용자 필드를 포함합니다). 그러나 이들은 독립적입니다. 예를 들어 환경 변수 설정을 상속하지 않습니다. 이 변경 사항은 Debian에만 적용됩니다. 아래 DEBIAN SPECIFIC 아래의 참고 사항을 참조하세요./etc/cron.d/etc/crontab/etc/crontab

와 마찬가지로 /etc/crontab디렉터리의 파일 /etc/cron.d변경 사항을 모니터링합니다. 일반적으로 시스템 관리자는 를 사용하지 /etc/cron.d/말고 표준 시스템 crontab 을 사용해야 합니다 /etc/crontab.

데비안 관련 섹션에서는 시스템 관리자가 이를 사용하지 말아야 하는 이유를 암시합니다 /etc/cron.d.

지원 /etc/cron.d(crontab 패키지의 디렉토리 삽입)

이는 패키지가 수정 없이 crontab 조각을 설치할 수 있도록 설계되었습니다 /etc/crontab.

관련 정보