linux의 crontab 명령어(CLI)는 현재 사용자에 대해 특정 시간 간격으로 실행되도록 하는 프로그램입니다.

기본 사용법

$> crontab -e
# 매분 마다 실행되는 작업(jobs)를 등록 합니다.
* * * * * echo "Hi Crontab."
# 작업을 등록하고 저장하면 아래와 같은 메시지를 볼 수 있습니다.
no crontab for geeksaga - using an empty one
crontab: installing new crontab

# 현재 설정된 작업 목록을 보여 줍니다.
$> crontab -l
* * * * * echo "Hi Crontab"

# 현재 사용자에 대한 작업을 모두 삭제 합니다.
$> crontab -r

실행 로그

RedHat-based 리눅스는 /var/log/cron 파일을 통해서 확인이 가능 합니다. Debian-based 리눅스는 /var/log/syslog 파일을 통해서 확인이 가능 합니다. Arch-based 리눅스는 journalctl 을 통해서 작업이 실행되었는지를 확인할 수 있습니다.

$> journalctl | rg CRON
...
Aug 24 16:38:01 newbie CROND[2249119]: (geeksaga) CMDEND (echo "Hi Crontab")
Aug 24 16:38:01 newbie CROND[2249119]: pam_unix(crond:session): session closed for user geeksaga
Aug 24 16:39:01 newbie CROND[2249316]: (geeksaga) CMD (echo "Hi Crontab")
Aug 24 16:39:01 newbie CROND[2249315]: (geeksaga) CMDOUT (Hi Crontab)
Aug 24 16:39:01 newbie CROND[2249315]: (geeksaga) CMDEND (echo "Hi Crontab")
Aug 24 16:39:01 newbie CROND[2249315]: pam_unix(crond:session): session closed for user geeksaga

help

$> crontab --help
crontab: invalid option -- '-'
crontab: usage error: unrecognized option
Usage:
 crontab [options] file
 crontab [options]
 crontab -n [hostname]

Options:
 -u <user>  define user
 -e         edit user's crontab
 -l         list user's crontab
 -r         delete user's crontab
 -i         prompt before deleting
 -n <host>  set host in cluster to run users' crontabs
 -c         get host in cluster to run users' crontabs
 -T <file>  test a crontab file syntax
 -V         print version and exit
 -x <mask>  enable debugging

Default operation is replace, per 1003.2

TLDR

$> tldr crontab

  crontab

  Schedule cron jobs to run on a time interval for the current user.
  More information: https://crontab.guru/.

  - Edit the crontab file for the current user:
    crontab -e

  - Edit the crontab file for a specific user:
    sudo crontab -e -u user

  - Replace the current crontab with the contents of the given file:
    crontab path/to/file

  - View a list of existing cron jobs for current user:
    crontab -l

  - Remove all cron jobs for the current user:
    crontab -r

  - Sample job which runs at 10:00 every day (* means any value):
    0 10 * * * command_to_execute

  - Sample crontab entry, which runs a command every 10 minutes:
    */10 * * * * command_to_execute

  - Sample crontab entry, which runs a certain script at 02:30 every Friday:
    30 2 * * Fri /absolute/path/to/script.sh

참고링크