0Pricing
Linux Command Line Mastery · Lektion

Aufgabenplanung: `cron` und `at`

Automatisieren Sie Aufgaben, die zu bestimmten Zeitpunkten oder in bestimmten Abständen ausgeführt werden, mithilfe von `cron`-Jobs und `at`-Befehlen.

Aufgabenplanung: `cron` und `at` ist eine kostenlose Linux Command Line Mastery-Lektion auf CoddyKit. Dies ist Lektion 1 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Linux Command Line Mastery-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Linux Command Line Mastery-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

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.

Häufig gestellte Fragen

Ist die Lektion „Aufgabenplanung: `cron` und `at`“ kostenlos?

Ja — der vollständige Text von „Aufgabenplanung: `cron` und `at`“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Linux Command Line Mastery-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Linux Command Line Mastery-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Aufgabenplanung: `cron` und `at`“?

Automatisieren Sie Aufgaben, die zu bestimmten Zeitpunkten oder in bestimmten Abständen ausgeführt werden, mithilfe von `cron`-Jobs und `at`-Befehlen. Du übst Linux Command Line Mastery mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Linux Command Line Mastery zu starten?

Keine Vorkenntnisse erforderlich. Linux Command Line Mastery auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 1 von 4.

Wie lange dauert die Lektion „Aufgabenplanung: `cron` und `at`“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Linux Command Line Mastery-Lektion Code schreiben und ausführen?

Ja. Jede Linux Command Line Mastery-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Aufgabenplanung: `cron` und `at`
  2. Dienstverwaltung: `systemctl` (systemd)
  3. Aufgaben mit Shell-Funktionen automatisieren
  4. Zentrales Logging und Rotation mit journald und logrotate
← Zurück zu Linux Command Line Mastery