Cron/ko

이 글은 젠투 리눅스의 크론 설치 및 사용법을 설명합니다.

크론이 하는 일
Cron is a daemon that runs scheduled tasks based on input from the command crontab. It accomplishes this task by waking up every minute and checking to see if there are any cron-jobs to run in any of the user crontabs.

사실상 표준이나 다름 없는 크론
There are a few cron implementations to choose from in Portage. All of them offer a similar interface, namely the use of crontab or a similar command. There is also a related utility called Anacron which is meant to work with cron on systems that are not continuously running.

에 따라 존재하는 모든 크론 패키지를 참고할 만 합니다. 언급한 패키지는 다른 어떤 크론 패키지에 기술적으로 의존하는건 아니지만, 대부분의 사용자가 만족할 수 있는 크론 같은 기능을 제공합니다.

Before getting started working with cron, a proper cron implementation has to be selected. In this article information is provided for each cron implementation available in Gentoo Linux.

vixie-cron
빅시 크론(Vixie-cron)은 SysV 크론 기반으로 완전한 기능을 갖춘 구현체입니다. 각각의 사용자는 자신의 크론탭을 지니고 있으며, 크론탭에 환경 변수를 지정할 수 있습니다. 다른 크론 변형과는 달리, SELinux와 PAM을 지원합니다. Dcron과는 적은 일부 아키텍처만 지원하지만, Fcron보다는 많이 지원합니다.

의 기능은 다음과 같습니다:


 * Support for SELinux;
 * Support for PAM ;
 * Setting of environment variables in crontabs (PATH, SHELL, HOME, etc.);
 * Each user can have a personal crontab; access is controlled by and

cronie
Cronie is a fork of vixie-cron done by Fedora. Because of it being a fork it has the same feature set the original vixie-cron provides. Additionally cronie comes with an anacron implementation which must be enabled through the  USE flag.

dcron (Dillon's Cron)
Dcron aims to be a simple, elegant and secure implementation of cron. It does not allow the specification of environment variables in crontabs and all cron-jobs are run from. Like vixie-cron, each user has his own crontab.

의 기능은 다음과 같습니다:


 * Fast, simple and free of unnecessary features;
 * Access to crontab is limited to the cron group, i.e. it doesn't rely on any external faculties.

fcron
fcron은 빅시 크론과 아나크론을 대체하는것이 목표입니다. 지속적으로 동작하지 않는 시스템에서 동작하도록 설쳬했으며 추가 기능을 포함했습니다. 작업 시작 강제, 작업 직렬화 관리, 작업에 적절한 값 할당, 시스템 시작히 실행할 작업 배치 능력을 보유하고 있습니다. 더 알아보시려면 fcron's 홈페이지를 보십시오.

의 기능은 다음과 같습니다:


 * Designed to work on systems that are not continuously running, i.e. it can run a job after restarting if it was missed;
 * Setting of environment variables and many other options in crontabs;
 * Enhanced crontab syntax with support for many new features;
 * Each user can have a personal crontab, access is controlled by and

bcron
bcron은 안전한 동작을 개념으로 하여 설계한 새로운 크론 시스템입니다. 이를 실행하려면 시스템은 몇가지로 나누어 놓은 프로그램으로 쪼개져야 하는데, 각각의 프로그램은 서로간의 통신을 엄격하게 관리하면서 각자 맏은 작업을 처리해야 합니다. 사용자 인터페이스는 비슷한 체계 의 기능을 대체하지만, 내부적으론 상당히 다릅니다. http://untroubled.org/bcron 홈페이지를 살펴보십시오.

의 기능은 다음과 같습니다:


 * Drop-in replacement for vixie-cron;
 * Multiprocess design;
 * Native daylight savings time support.

아나크론
아나크론(Anacron)은 크론 데몬이 아니고 크론과 같이 동작하는 프로그램입니다. 지정한 날짜 간격대로 명령을 실행하며 시스템이 계속 동작함을 고려하진 않습니다. 시스템이 멈추었을때 놓친 작업을 실행합니다. 아나크론은 보통 각각의 날짜별로 실행할 크론 데몬과 관련이 있습니다.

설치
Select the right cron implementation for the job, and then emerge it:

Make sure the cron daemon of choice has been added to the system's init process; without this step the cron daemon will not perform its job.

Optionally, if Fcron has not been installed, installing Anacron as a helper to the cron daemon might be a wise choice.

Again, do not forget to add anacron to the system's init process.

시스템 크론탭
The post install messages from some of these cron packages instruct the user to run crontab /etc/crontab. The file is the system crontab. A cron installation can use it in conjunction with to run the scripts in. Note that only vixie-cron and cronie schedule jobs in automatically. Dcron and fcron users will need to run crontab /etc/crontab every time they make changes to the file.

Please note that jobs scheduled in the system crontab might not show up in the list of cron-jobs displayed by running crontab -l.

Of course, users can choose not to use any system crontab at all. If dcron or fcron has been chosen, do not run crontab /etc/crontab. If vixie-cron, cronie or bcron has been chosen comment all lines in.

A quick and easy way to comment out all the lines in a file is by using the sed command. Run the following command to comment out all the lines in

신뢰하는 사용자에게 크론 접근 권한 부여하기
For users other than root to have access to the cron daemon, read this section, otherwise proceed to the next section: Scheduling cron-jobs.

No matter which cron package has been chosen, to allow a user to use crontab he will first have to be in the cron group. As an example, to add the user wepy to the cron group run:

When using dcron, the above step is all that is needed to give a user access to crontab. Dcron users may proceed to the next section Scheduling cron-jobs, all others need to keep reading.

When using fcron, edit the and  files. The most secure way to run a system is to first deny all users in, and then explicitly allow users in.

If a user (wepy again for this example) should be able to schedule his own cron-jobs, then add him to as follows:

If vixie-cron or cronie has been chosen, then simply edit the file.

For example, to allow access to the user wepy, add him to as follows:

크론 작업 일정 설정
The process of editing crontabs is different for each package, but they all support the same basic set of commands: adding and replacing crontabs, editing crontabs, deleting crontabs, and listing cron-jobs in crontabs. The following list shows how to run various commands for each package.

Before any of these commands can be used, first understanding of the crontab itself is needed. Each line in a crontab specifies five time fields in the following order: the minutes (0-59), hours (0-23), days of the month (1-31), months (1-12), and days of the week (0-7, Monday is day 1, Sunday is day 0 and day 7). The days of the week and months can be specified by three-letter abbreviations like mon, tue, jan, feb, etc. Each field can also specify a range of values (e.g. 1-5 or mon-fri), a comma separated list of values (e.g. 1,2,3 or mon,tue,wed) or a range of values with a step (e.g. 1-6/2 as 1,3,5).

That sounds a little confusing, but with a few examples it is easy to see it is not as complicated as it sounds.

To test what was just covered go through the steps of actually inputting a few cron-jobs. First, create a file called and make it look like the this:

Now add that crontab to the system with the "new command" from the table above.

To verify the scheduled cron-jobs, use the proper list command from the table above.

A list resembling should be displayed; if not maybe the wrong command was issued to input the crontab.

This crontab should echo "I really like cron" every minute of every hour of every day every other month. Obviously a user would only do that if they really liked cron. The crontab will also echo "I like cron a little" at 16:30 every day in January and February. It will also echo "I don't really like cron" at 3:10 on the January 1st.

If using anacron keep reading this section. Otherwise, proceed to the next section on Editing crontabs.

아나크론 사용자는 파일을 편집하려 할 것입니다. 이 파일은 매 실행 일자 간격, 실행 후 지연 시간, 작업 이름, 실행할 명령 네가지 내용으로 구성되어 있습니다.

For example, to have it run echo "I like anacron" every 5 days, 10 minutes after anacron is started, enter the following:

Anacron exits after all of the jobs in anacrontab have finished. To check to see if these jobs should be performed every day, a cron daemon will be used. The instructions at the end of the next section explain how this should be handled.

크론탭 편집
Being realistic, no user would want their system telling them how much they like cron every minute. As a step forward, remove the previous example crontab using the corresponding remove command from the table above. Use the corresponding list command to view the cron-jobs afterward to make sure it worked.

No cron-jobs should be displayed in the output from crontab -l</tt>. If cron jobs are listed, then the remove command failed to remove the crontab; verify the correct remove command for the system's cron package.

Now that we have a clean state, let's put something useful into the root crontab. Most people will want to run updatedb</tt> on a weekly basis to make sure that mlocate works properly. To add that to the system's crontab, first edit again so that it looks like the following:

That would make cron run updatedb at 2:22 A.M. on Monday morning every week. Now input the crontab with the proper new command from the table above, and check the list again.

Now let's say emerge --sync</tt> should be ran on a daily schedule in order to keep the Portage tree up to date. This could be done by first editing and then using crontab crons.cron</tt> as was done in the example above, or by using the proper edit command from the table above. This provides a way to edit the user's crontab in situ, without depending on external files like.

The above command should open the user's crontab with an editor. For example, if emerge --sync</tt> is to be run every day at 6:30 A.M., make the crontab look something like this:

Again, check the cron-jobs list as done in the previous examples to make sure the jobs are scheduled. If they are all there, then the system is ready to rock and roll.

크론 베이스 사용
As mentioned earlier, all of the available cron packages depend on. The cronbase package creates, and a script called. Notice the default file contains something like this:

To avoid going into much detail, assume these commands will effectively run hourly, daily, weekly and monthly scripts. This method of scheduling cron-jobs has some important advantages:


 * They will run even if the computer was off when they were scheduled to run;
 * It is easy for package maintainers to place scripts in those well defined places;
 * The administrators know exactly where the cron-jobs and crontab are stored, making it easy to backup and restore these parts of their systems.

아나크론 사용
As mentioned earlier, anacron is used on systems not meant to be run continuously (like most of the desktop installations). Its default configuration file,, is usually similar to the following:

The main difference between this and other common crontabs is that with anacron there is no fixed date/hour for the job scheduling, but only the period between every run. When anacron is started, it will check the contents of a set of files in and calculate if the corresponding entry in the configuration file has expired since the last run. If it has, then the command is invoked again.

마지막 참고할 사항으로, 다음 vixie-crom 크론탭 예제에서와 같이 시스템에 설치한 다른 크론의 중복 적용 항목을 주석처리하는것이 매우 중요합니다.

이 동작을 처리하지 않으면, 일일, 주간, 월간 부분의 각기 다른 부분을 - 각자 다른 시간에 - 크론 데몬과 아나크론이 실행하여 작업을 두번 실행하도록 유발합니다.

마지막 참고
Remember, each cron package is different and the range of features varies greatly. Be sure to consult the man pages for crontab, fcrontab or anacrontab, depending on which cron daemon has been used.

행운을 빕니다 :-P !

문제 해결
When having problems getting cron to work properly, this quick checklist might be helpful.

크론이 실행하는 중인가요?
To verify that cron is running, see if it shows up in the process list:

크론이 동작중인가요?
다음 명령을 실행해보세요:

다음 이 주기적으로 바뀌는지 확인해보세요.

Is the command working?
이전과 마찬가지지만, 표준 오류 출력을 있는 그대로 리다리렉트 해야 합니다:

Can cron run the job?
보통 에서, 오류 내용은 에서 크론 로그를 확인해보세요.

가 있나요?
cron usually sends mail when there is a problem; check for mail and look for the creation of a file.

대응 크론 프로그램
Some hosting companies do not allow access to cron, but many cron jobs alternatives can be found which are free or commercially available:


 * EasyCron