Introduction
As a system administrator, automating tasks is a core responsibility. The at and cron utilities are fundamental tools for scheduling tasks on Linux. In this challenge, you will practice using at to schedule a one-time job and cron to schedule a recurring job.
Schedule a One-Time Task with at
The at command is used to schedule commands to be executed once at a particular time in the future.
Tasks
- Use the
atcommand to schedule a task to run in one minute. - Verify that the task creates a file with the specified content.
Requirements
- Schedule a task to run one minute from now.
- The task must execute the command
echo "This is a scheduled task" > /home/labex/project/scheduled_task.txt. - After the task executes, the file
/home/labex/project/scheduled_task.txtmust exist and contain the textThis is a scheduled task.
Example
After the task has executed, the content of /home/labex/project/scheduled_task.txt should be:
This is a scheduled task
Hints
- Use the time specification
now + 1 minuteto schedule the task. - After entering the
atcommand, you will be at a new prompt. Type your command and press Enter. - To save the job and exit the
atprompt, pressCtrl+D.
Schedule a Recurring Task with cron
The cron daemon is used to execute scheduled commands at regular intervals. You can manage your scheduled tasks using the crontab command.
Tasks
- Create a cron job that runs a command every minute.
- Verify that a log file is created and updated by the cron job.
Requirements
- Use the
crontab -ecommand to edit your user's crontab. - Add a cron job that executes the command
echo "This is a recurring task" >> /home/labex/project/recurring_task.log. - The job must be configured to run every minute of every hour, every day.
- The file
/home/labex/project/recurring_task.logshould be created and appended with new text every minute.
Example
After the cron job has run for a few minutes, the contents of /home/labex/project/recurring_task.log should look similar to this:
This is a recurring task
This is a recurring task
This is a recurring task
Hints
- The
crontab -ecommand will open your crontab file in a text editor (usuallyvi). - The format for a cron job that runs every minute is
* * * * * command_to_run. - If the editor is
vi, pressito enter insert mode, type your line, pressEscto exit insert mode, and then type:wqand press Enter to save and quit.
Summary
In this challenge, you have learned how to automate tasks on a Linux system. You practiced scheduling a one-time job for future execution using the at command and setting up a recurring task with cron by editing a crontab. These are essential skills for any system administrator to manage routine maintenance and other automated processes.



