Loading...

Lab 42: One-Time Job Scheduling with at

Schedule a one-time backup job to run at 2:30 AM tomorrow using at, then verify and inspect the queued job. Confirm the job content with at -c and remove it with atrm to simulate a cancellation.

services core troubleshooting

Scenario

A user requests that a heavy backup job run exactly once at 2:30 AM tomorrow so it does not impact daytime performance. You need to confirm the scheduling service is running, queue the job properly, and prove it is in the queue with the correct command content.

Operator context

One-time scheduling is ideal for maintenance tasks that should run outside peak hours without creating recurring cron entries that get forgotten later.

Objective

  • Confirm the atd service is running.
  • Schedule /home/dev/backup.sh for 2:30 AM tomorrow.
  • Verify the job is queued using atq.
  • Inspect the job content using at -c.
  • Remove the job using atrm.

What You’ll Practice

  • Verifying daemon state with systemctl status.
  • Scheduling one-time tasks by piping commands into at.
  • Queue verification using atq.
  • Auditing queued jobs using at -c.
  • Safe cleanup and cancellation using atrm.

Walkthrough

Step 1 : Check if the atd daemon is running.
Command
systemctl status atd

at relies on the atd scheduler service. If atd is not active, jobs will not run when scheduled.

● atd.service - Deferred execution scheduler
   Loaded: loaded (/lib/systemd/system/atd.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2025-07-22 09:41:37 UTC; 1h 23min ago
     Docs: man:atd(8)
 Main PID: 672 (atd)

Jul 22 09:41:37 lpic-lab42 systemd[1]: Started Deferred execution scheduler.
Step 2 : Schedule the backup script for 2:30 AM tomorrow.
Command
echo '/home/dev/backup.sh' | at 2:30 AM tomorrow

Piping a command into at queues it to run once at the specified time. The scheduler assigns a job number you can use to inspect or remove it later.

job 8 at Thu Jul 25 02:30:00 2025
Step 3 : Verify the job is queued.
Command
atq

atq lists queued one-time jobs. Use this to confirm the job exists and is scheduled for the intended time.

8  Thu Jul 25 02:30:00 2025 a vonds
Step 4 : Inspect the queued job content.
Command
at -c 8

at -c prints the full script that will be executed, including environment setup. This is how you prove the job runs the exact command you intended.

#!/bin/sh
# atrun uid=1000 gid=1000
# mail vonds 0
umask 22
cd /home/vonds || {
  echo 'Execution directory inaccessible'; exit 1;
}
/home/dev/backup.sh
Step 5 : Remove the queued job to simulate cancellation.
Command
atrm 8

atrm cancels a queued job by job number. Use this when the user changes their mind or the maintenance window is rescheduled.

Job 8 removed.

Reference

  • systemctl status atd : Confirms whether the deferred execution scheduler (atd) is active.
  • at <time> : Queues commands to run once at a specified time.
    • Example: echo '/path/script.sh' | at 2:30 AM tomorrow
  • atq : Lists queued at jobs.
  • at -c <jobid> : Displays the full script that will be executed for a queued job.
  • atrm <jobid> : Removes a queued job from the at queue.
  • atd : The daemon that executes at jobs.