Cron/ko

이 안내서는 크론 설치 및 사용법을 설명합니다.

크론이 하는 일
크론은 에 입력한 명령을 기반으로 하여 일정에 따라 계획한 작업을 실행하는 데몬입니다. 각 시간마다 작업을 실행하며 사용자 크론탭을 실행할 크론 작업이 있는지 살펴보는 역할을 합니다.

사실상 표준이나 다름 없는 크론
포티지에는 골라 사용할 수 있는 여러가지 크론 구현체가 있습니다. 이라고 알려진 이름의 수단 또는 유사 명령으로 사용하는 비슷한 인터페이스를 제공합니다. 관련 유틸리티로는 아나크론(Anacron)이 있는데 계속 동작하지 않는 시스템의 크론과 함께 동작함을 의미합니다.

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

크론을 다루기 전에, 사용하려는 구현제를 선택해야 합니다. 편의를 위해 각각에 대한 내용을 아래에 모아보았습니다.

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

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


 * SELinux 지원
 * PAM 지원
 * 크론탭에서의 환경변수 설정 (PATH, SHELL, HOME 등)
 * 각각의 사용자가 크론탭을 보유할 수 있습니다. 와 에서 접근 권한을 다룹니다.

cronie
크로니(Cronie) (sys-process/cronie)는 페도라가 vixie-cron에서 분리한 꾸러미입니다. 원래 빅시 크론에서 제공하는 동일한 기능 모음을 제공하려는 것이 이유입니다. 게다가 anacron 구현체로서 크로니를 사용하려면 anacron USE 플래그를 활성화해야 합니다.

dcron (Dillon's Cron)
dcron의 목표는 단순하고 우아하며 안전한 크론 구현체입니다. 크론탭의 환경 변수 지정을 허용하지 않으며 모든 크론 작업은 에서 실행합니다. 빅시 크론과 비슷하게 각각의 사용자는 자신의 크론탭을 지닙니다.

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


 * 빠르고 단순하며 필요없는 기능으로부터 자유롭습니다.
 * 의 접근은 cron 그룹으로 제한합니다. 예를 들어 다른 조직(그룹)과는 관련이 없습니다.

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

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


 * 계속 동작하지 않는 시스템에서 동작하도록 설계함. 예를 들어 작업을 놓쳤을 경우에도 다음에 다시 시작할 때 작업을 실행할 수 있음
 * 크론탭에서 환경 변수와 기타 옵션을 설정할 수 있음
 * 각각의 사용자는 크론탭을 보유하며 cron.allow와 cron.deny로 관리함
 * 많은 새로운 기능을 지원하여 크론 문법을 개선

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

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


 * 빅시 크론 기능 대체
 * 멀티 프로세싱 설계
 * 자체 일광 절약 시간 기능 지원

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

설치
사용하고 싶은 크론 구현체를 고른후 이머지 하십시오.

추가적으로 Fcron을 설치하지 않았다면 Anacron을 설치해도 됩니다.

System crontab
The post install messages from some of these cron packages tell you to run. The file is your 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  every time they make changes to.

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

Of course, you can choose not to use any system crontab at all. If you chose dcron or fcron, do not run. If you chose vixie-cron, cronie or bcron, you should comment all lines in.

Giving trusted users access to cron
If you want users other than root to have access to the cron daemon, you'll want to read this section, otherwise, you can proceed to the next section, Scheduling cron-jobs.

No matter which cron package you use, if you want to allow a user to use crontab, he will first have to be in the cron group. As an example, if you wanted to add the user wepy to the cron group you would run:

If you're using dcron, that's all you have to do to give a user access to crontab. Dcron users may proceed to the next section Scheduling cron-jobs, all others will want to keep reading.

If you're using fcron, you'll want to edit and. The most secure way is to first deny everyone in, and then explicitly allow users in.

Permissions in fcron.deny

Now, say we have a user wepy who should be able to schedule his own cron-jobs. We would add him to as follows:

Permissions in fcron.allow

If you chose vixie-cron or cronie, you'll probably just want to edit.

For example, if you wanted to allow access to the user wepy, you would add him to as follows:

Permissions in /etc/cron.allow

Scheduling cron-jobs
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 you how to run those commands for each package.

Before we can use any of these commands though, you first need to understand the crontab itself. Each line in a crontab needs to specify 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 1, Sunday is 0 and 7). The days of the weeks 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, you will see that it is not as complicated as it sounds.

Examples

To test what we have just learned, let's go through the steps of actually inputting a few cron-jobs. First, create a file called and make it look like the this:

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

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

You should see a list resembling, if not, maybe you used the wrong command to input your new crontab.

This crontab should echo "I really like cron" every minute of every hour of every day every other month. Obviously you would only do that if you 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 you are using anacron, you should keep reading this section. Otherwise, proceed to the next section on Editing crontabs.

Anacron users will want to edit. This file has four fields: the number of days between each run, the delay in minutes after which it runs, the name of the job, and the command to run.

For example, to have it run  every 5 days, 10 minutes after anacron is started, you would have:

/etc/anacrontab

Anacron exits after all of the jobs in anacrontab are done, so if we want it to check these jobs every day, we will need to use cron. The instructions at the end of the next section tell you how to do that.

Editing crontabs
Let's be realistic though, you don't want your system telling you how much you like cron every minute. As a step forward, let's remove that crontab using the corresponding remove command from the table above. We will also list the cron-jobs after, just to make sure it worked.

You should see no cron-jobs in the output from. If you do see jobs listed, that means we failed to remove the crontab, and that you should make sure that you used the correct remove command for your cron package.

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

A real crontab

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

Now let's say that you also want to add  to your daily schedule. You could do this by first editing and then using   just as we did before, or you could use the proper edit command from the table above. This gives you a way to edit your user's crontab in situ, without depending on external files like.

That should open your user's crontab with an editor. We want to have  run every day at 6:30 A.M., so we'll make it look something like this:

A real crontab

Again, check the cron-jobs list as we did in the previous examples to make sure the jobs are scheduled. If they are all there, then you're all set.

Using cronbase
As mentioned earlier, all of the available cron packages depend on. The cronbase package creates, and a script called. You might have noticed that the default contains something like this:

Default system crontab

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


 * They will run even if your computer was off when they were scheduled to run
 * It is easy for package maintainers to place scripts in those well defined places
 * You know exactly where your cron-jobs and your crontab are stored, making it easy for you to backup and restore this part of your system

Using anacron
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 like the following:

As you see 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.

As a final note, it is important to comment out any overlapping entry in any other cron installed in the system, such as in the following vixie-cron crontab example:

Without doing this, the daily, weekly and monthly parts will be executed - at different times - by both the cron daemon and anacron, leading to possible double job executions.

Final Notes
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 what you use.

Good luck!

Troubleshooting
If you're having problems getting cron to work properly, you might want to go through this quick checklist.

Is cron running?
Run  and make sure it shows up!

Is cron working?
Try the following:

crontab to see if cron is running

Then check if is modified periodically.

Is your command working?
Same as before, but perhaps redirect the standard error output as well:

crontab to verify application runs

Can cron run your job?
Check the cron log, usually or  for errors

Are there any s?
cron usually sends mail when there's a problem; check your mail and also look for.

Acknowledgements
We would like to thank the following authors and editors for their contributions to this guide:


 * Eric Brown
 * Xavier Neys
 * nightmorph