0Pricing
Linux Command Line Mastery · 강의

작업 예약: `cron`과 `at`

`cron` 작업과 `at` 명령을 사용하여 특정 시간이나 간격에 작업이 실행되도록 자동화합니다.

작업 예약: `cron`과 `at`은(는) CoddyKit의 무료 Linux Command Line Mastery 강의입니다. 이것은 4개 중 1번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Linux Command Line Mastery 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Linux Command Line Mastery 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Automating Your Linux Tasks

In Linux, you often need to run tasks automatically. This could be anything from backing up files to generating reports.

Automation saves time and ensures tasks are performed consistently, even when you're not actively at the keyboard.

Introducing `cron` for Recurring Jobs

cron is a powerful utility that helps you schedule commands or scripts to run automatically at specific intervals. Think of it as your personal assistant for repetitive tasks!

These scheduled tasks are often called "cron jobs".

Your Personal `crontab` File

Each user has their own crontab file, which lists their scheduled cron jobs.

  • To edit your crontab: crontab -e
  • To list your current jobs: crontab -l
  • To remove all your jobs: crontab -r (use with caution!)

When you edit, it typically opens in a text editor like Nano or Vim.

crontab -e

Understanding `cron` Job Structure

A cron job entry has six parts:

minute hour day_of_month month day_of_week command_to_execute
  • Minute: 0-59
  • Hour: 0-23 (0 is midnight)
  • Day of Month: 1-31
  • Month: 1-12 (or Jan-Dec)
  • Day of Week: 0-7 (0 or 7 is Sunday)

An asterisk (*) means "every" value for that field.

Practical `cron` Examples

Let's look at some common cron job examples you might add to your crontab file.

# Run a script every day at 3:00 AM
0 3 * * * /home/user/daily_backup.sh

# Run a command every Sunday at 10:30 PM
30 22 * * 0 echo "Weekly check!" >> /var/log/weekly.log

# Run every 15 minutes
*/15 * * * * /usr/bin/some_utility

Handy `cron` Shortcuts

For common schedules, cron offers special keywords:

  • @reboot: Run once after system startup.
  • @hourly: Run once an hour.
  • @daily: Run once a day (midnight).
  • @weekly: Run once a week (midnight Sunday).
  • @monthly: Run once a month (midnight on 1st).
  • @yearly: Run once a year (midnight on Jan 1st).

These keywords replace the first five time fields.

Scheduling Single Tasks with `at`

While cron is for recurring tasks, the at command is perfect for scheduling a command to run only once at a specified future time.

It's useful for tasks that don't need to repeat, like running a report at the end of the day or a specific cleanup task.

How to Use the `at` Command

To schedule a task with at, you provide the time and then type the command(s) you want to run. Press Ctrl+D to finish.

Here's how to schedule a simple message to appear in 1 minute:

echo "echo 'Task completed by at!'" | at now + 1 minute

Managing Your `at` Queue

You can manage your scheduled at jobs:

  • To list all pending at jobs: atq
  • To remove a specific job: atrm [job_number]

Each job listed by atq will have a unique job number.

# List all pending 'at' jobs
atq

# Remove the job with ID 42
atrm 42

`cron` & `at` Quick Check

Consider the following scenario:

You need to schedule a script named /opt/cleanup.sh to run every Tuesday at 4:45 AM.

Which crontab entry correctly achieves this?

Recap: `cron` and `at`

Great job! You've learned how to automate tasks on Linux:

  • cron is for scheduling recurring jobs using a `crontab` file and specific time syntax.
  • at is for scheduling commands to run once at a future time.

These tools are essential for system administration and keeping your systems running smoothly without constant manual intervention.

자주 묻는 질문

“작업 예약: `cron`과 `at`” 강의는 무료인가요?

네 — “작업 예약: `cron`과 `at`” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Linux Command Line Mastery 강의 전체를 잠금 해제할 수 있습니다. Linux Command Line Mastery 강의에는 총 4개의 강의가 포함되어 있습니다.

“작업 예약: `cron`과 `at`”에서 뭘 배우나요?

`cron` 작업과 `at` 명령을 사용하여 특정 시간이나 간격에 작업이 실행되도록 자동화합니다. 브라우저에서 직접 실행하는 실습 코드로 Linux Command Line Mastery을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Linux Command Line Mastery을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Linux Command Line Mastery은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 1번째 강의입니다.

“작업 예약: `cron`과 `at`” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Linux Command Line Mastery 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Linux Command Line Mastery 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 작업 예약: `cron`과 `at`
  2. 서비스 관리: `systemctl` (systemd)
  3. 셸 함수로 작업 자동화
  4. journald와 logrotate로 중앙 로그 기록과 순환 관리하기
← Linux Command Line Mastery(으)로 돌아가기