
Linux에서 Cron 작업을 보거나 나열하는 방법
Cron 이름은 시간을 나타내는 그리스어 Chronos에서 유래했습니다. Linux 시스템이 지정된 시간 간격으로 명령 또는 스크립트 실행을 자동화하는 데몬입니다. 이 자습서에서는 Linux 시스템의 사용자를 위해 예약된 모든 cron 작업을 나열하는 몇 가지 옵션을 보여줍니다.
모든 사용자 cron 작업은 일반적으로/var/spool/cron/crontabs 디렉토리에 있습니다. 해당 이름을 가진 모든 사용자 계정에 대해 별도의 파일이 생성됩니다.
현재 사용자의 Cron 작업을 나열하는 방법
기본 crontab 명령은 현재 로그인한 사용자에 대해 작동합니다. 현재 사용자에 대해 예약된 모든 크론 작업을 나열할 수 있습니다. 실행:crontab –l
출력: 
다른 사용자의 Cron 작업 나열
루트 또는 sudo 권한이 있는 사용자는 다른 사용자의 예약된 cronjob도 볼 수 있습니다. -u 다음에 사용자 이름을 사용하여 특정 사용자에게 속한 모든 작업을 나열합니다. 예:sudo crontab –u username –l
사용자 이름을 크론 작업을 보려는 실제 사용자 이름으로 바꿉니다. 시스템에서 실행 중인 Cron 작업 나열
루트 사용자는 운영 체제의 crontab에 액세스하고 수정할 수 있습니다. 루트 또는 sudo 권한 계정으로 다음 명령을 실행하여 시스템의 cronjob을 볼 수 있습니다.less /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 # Example of job definition: # .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | | # * * * * * user-name command to be executed 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 )
시간별 Cron 작업을 나열하는 방법
/ettc/cron.hourly 디렉토리에서 매시간 실행되도록 예약된 모든 cron 작업을 찾을 수 있습니다.ls -la /etc/cron.hourly
출력: total 20 drwxr-xr-x 2 root root 4096 Apr 23 2020 . drwxr-xr-x 142 root root 12288 Jan 19 15:21 .. -rw-r--r-- 1 root root 102 Feb 14 2020 .placeholder위의 출력은 매시간 실행할 cron 작업 일정이 없음을 보여줍니다. 패키지 관리자가 실수로 디렉토리를 삭제하지 않도록 각 디렉토리에서 .placeholder 파일을 볼 수 있습니다. 디렉토리에 다른 파일이 없을 때.
일일 Cron 작업을 나열하는 방법
마찬가지로 매일 실행하도록 예약된 모든 작업을 나열할 수 있습니다. 대부분의 응용 프로그램 작업은 이 디렉터리에서 찾을 수 있습니다.ls -la /etc/cron.daily
출력: total 72 drwxr-xr-x 2 root root 4096 Dec 28 15:28 . drwxr-xr-x 142 root root 12288 Jan 19 15:21 .. -rwxr-xr-x 1 root root 311 Jul 16 2019 0anacron -rwxr-xr-x 1 root root 539 Apr 13 2020 apache2 -rwxr-xr-x 1 root root 376 Dec 5 2019 apport -rwxr-xr-x 1 root root 1478 Apr 9 2020 apt-compat -rwxr-xr-x 1 root root 355 Dec 29 2017 bsdmainutils -rwxr-xr-x 1 root root 384 Nov 19 2019 cracklib-runtime -rwxr-xr-x 1 root root 1187 Sep 6 2019 dpkg -rwxr-xr-x 1 root root 377 Jan 21 2019 logrotate -rwxr-xr-x 1 root root 1123 Feb 25 2020 man-db -rw-r--r-- 1 root root 102 Feb 14 2020 .placeholder -rwxr-xr-x 1 root root 4574 Jul 18 2019 popularity-contest -rwxr-xr-x 1 root root 383 Jan 6 2020 samba -rwxr-xr-x 1 root root 214 Apr 2 2020 update-notifier-common
주간 크론 작업을 나열하는 방법
주간 크론 작업은/etc/cron.weekly 디렉토리에서 예약됩니다.ls -la /etc/cron.weekly
출력: total 32 drwxr-xr-x 2 root root 4096 Apr 23 2020 . drwxr-xr-x 142 root root 12288 Jan 19 15:21 .. -rwxr-xr-x 1 root root 312 Jul 16 2019 0anacron -rwxr-xr-x 1 root root 813 Feb 25 2020 man-db -rw-r--r-- 1 root root 102 Feb 14 2020 .placeholder -rwxr-xr-x 1 root root 211 Apr 2 2020 update-notifier-common
월별 Cron 작업을 나열하는 방법
모든 월별 cron 작업은/etc/cron.monthly 디렉토리에서 예약됩니다.ls -la /etc/cron.monthly
출력: total 24 drwxr-xr-x 2 root root 4096 Apr 23 2020 . drwxr-xr-x 142 root root 12288 Jan 19 15:21 .. -rwxr-xr-x 1 root root 313 Jul 16 2019 0anacron -rw-r--r-- 1 root root 102 Feb 14 2020 .placeholder
애플리케이션별 Cron 작업을 보는 방법
응용 프로그램의 5월은 정기적인 작업을 위해 cron 작업을 예약했습니다. 이러한 작업은 시간별, 일별, 주별 또는 월별 cron 작업에서 찾을 수 있습니다. 예를 들어 Apache 웹 서버는/etc/cron.daily에서 cron 작업 파일을 생성했습니다. 작업이 매일 실행됨을 의미합니다. 다음과 같이 파일 내용에 액세스하여 크론 작업 내용을 볼 수 있습니다.cat /etc/cron.daily/apache2
출력: #!/bin/sh # run htcacheclean if set to 'cron' mode set -e set -u type htcacheclean > /dev/null 2>&1 || exit 0 [ -e /etc/default/apache-htcacheclean ] || exit 0 # edit /etc/default/apache-htcacheclean to change this HTCACHECLEAN_MODE=daemon HTCACHECLEAN_RUN=auto HTCACHECLEAN_SIZE=300M HTCACHECLEAN_PATH=/var/cache/apache2/mod_cache_disk HTCACHECLEAN_OPTIONS="" . /etc/default/apache-htcacheclean [ "$HTCACHECLEAN_MODE" = "cron" ] || exit 0 htcacheclean ${HTCACHECLEAN_OPTIONS} \ -p${HTCACHECLEAN_PATH} \ -l${HTCACHECLEAN_SIZE}