유저 크론탭

$ crontab -e
$ crontab -e USERNAME #root유저일 때

유저마다 크론탭을 따로 설정해줄 수 있다. 자기 자신에게 추가하는 작업일 경우 딱히 권한을 필요로 하지 않으므로 해당 명령을 통해 간단하게 반복될 작업을 추가할 수 있다. 명령을 실행하면 crontab 파일을 수정하는 화면으로 이동하며 /etc/crontab을 수정하는 것과 마찬가지로 작업을 추가하면 된다.

주의할 점은 유저이름을 쓰는 필드가 없다는 것이다. 유저 크론탭이므로 다른 유저가 사용할 일이 없기 때문이다. 그래서 유저이름을 써버리면 그것도 명령어로 인식해버려서 계속 실패하게 되는데, 문제는 주석을 자세히 읽지 않으면 이를 알 수가 없다. 딱히 에러 메시지가 친절한 것도 아니니까 말이다.

유저 크론탭이 저장되는 위치는 우분투 기준 /var/spool/cron/crontabs이며, 해당 디렉토리 내 유저이름으로 된 파일로 저장된다. 만약 유저이름이 username일 경우, 파일 경로와 내용은 아래와 같다.

/var/spool/cron/crontabs$ ls -la
total 12
drwx-wx--T 2 root     crontab 4096  1월 19 05:35 .
drwxr-xr-x 3 root     root    4096  9월 12  2016 ..
-rw------- 1 username crontab 1335  1월 19 05:35 username

/var/spool/cron/crontabs$ cat USERNAME
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.0k7MLv/crontab installed on Sat Jan 19 05:32:03 2019)
# (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command