Schedule Tasks Using at and Cron

LinuxLinuxBeginner
Practice Now

Introduction

As a system administrator, you are responsible for automating various tasks on your Linux system. Two common tools for scheduling tasks are at and cron. In this challenge, you will learn how to use these tools to schedule tasks and ensure they run as expected.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/BasicSystemCommandsGroup(["`Basic System Commands`"]) linux/BasicSystemCommandsGroup -.-> linux/echo("`Text Display`") subgraph Lab Skills linux/echo -.-> lab-389475{{"`Schedule Tasks Using at and Cron`"}} end

Schedule a One-Time Task Using at

Tasks

  • Schedule a one-time task to run at a specific time in the future.
  • Verify that the task runs as scheduled.

Requirements

  • The task should run the command echo "This is a scheduled task" > ~/project/scheduled_task.txt at a specific time in the future.
  • The file ~/project/scheduled_task.txt should be created and contain the text "This is a scheduled task".

Example

After the task is scheduled, the contents of ~/project/scheduled_task.txt should be:

This is a scheduled task

Schedule a Recurring Task Using cron

Tasks

  • Schedule a recurring task to run every minute.
  • Verify that the task runs as scheduled.

Requirements

  • The task should run the command echo "This is a recurring task" >> ~/project/recurring_task.log every minute.
  • The file ~/project/recurring_task.log should be created and contain the text "This is a recurring task" appended to it every minute.

Example

After the task is scheduled, the contents of ~/project/recurring_task.log should look similar to:

This is a recurring task
This is a recurring task
This is a recurring task
This is a recurring task

Summary

In this challenge, you learned how to use the at and cron commands to schedule one-time and recurring tasks on a Linux system. You practiced scheduling a task to run at a specific time in the future using at, and scheduling a task to run every minute using cron. You also learned how to verify that the tasks ran as expected by checking the output files. These skills are essential for automating routine system maintenance and administrative tasks.

Other Linux Tutorials you may like