Loading...

Lab 42: One-Time Job Scheduling with at

Schedule a one-time backup run for the next maintenance window using at and prove it is queued with the expected command. Inspect the generated job script with at -c and cancel it cleanly with atrm .

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 scheduler is available, queue the job correctly, and validate that the queued content matches the intended command.

Operator context

Use at for one-off maintenance work that should not become a recurring cron entry. Always verify the queue and job body so you can prove what will run before the window opens.

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 .

Concepts

  • The at queue for one-time execution versus cron for recurring jobs.
  • Dependency on the scheduler daemon ( atd ) to execute queued work.
  • Queue inspection and ownership visibility ( atq ).
  • Job body verification using at -c (expanded environment + command payload).
  • Cancellation workflow using atrm to avoid stale scheduled work.

Walkthrough

Step 1 : Confirm the scheduler daemon is running.
Command
systemctl status atd

at depends on atd to execute queued jobs. If the daemon is inactive, the job may be accepted but will not run on schedule.

● 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 : Queue the backup script for 2:30 AM tomorrow.
Command
echo '/home/dev/backup.sh' | at 2:30 AM tomorrow

Piping commands into at queues them for one-time execution at the specified time. The scheduler returns a job number that becomes your handle for inspection and cancellation.

job 8 at Thu Jul 25 02:30:00 2025
Step 3 : Verify the job exists in the queue.
Command
atq

atq lists queued jobs, including job ID, scheduled time, and job owner. This is your primary verification that the job is pending.

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

at -c prints the exact script that will run, including environment setup and the command payload. Use this to validate that the queued work matches the approved change.

#!/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 : Cancel the job cleanly.
Command
atrm 8

Use atrm to remove a queued job by job number. This prevents stale scheduled work from running after a maintenance window changes.

# Verify removal:
atq

Common breakpoints

atd is inactive

If systemctl status atd shows the service is not running, queued jobs will not execute. Start and enable the service, then re-queue the job and verify it appears in atq .

Job is queued but command is wrong

Always inspect with at -c <jobid> before the window opens. If the command payload is wrong, remove the job with atrm and queue it again rather than trying to “patch” it.

Time specification schedules the wrong day

Human-friendly specs can be misread. Confirm the resolved schedule in the at output and in atq before you leave the change window.

Permissions or allow/deny restrictions

If job submission fails, check /etc/at.allow and /etc/at.deny policy and validate the user is permitted to schedule jobs. Confirm daemon logs if the failure is not explicit.

Cleanup checklist

This lab should leave no persistent configuration changes. Your cleanup is ensuring the queue is clear and no unintended jobs remain scheduled.

Commands
atq
systemctl status atd
Success signal

atq returns no pending jobs, and atd is active so future approved one-time work can run.

Reference

  • systemctl status atd : Shows whether the atd service is active.
    • status : Displays current state and recent journal output.
  • echo '<cmd>' | at <time> : Queues a one-time job by passing commands to at via standard input.
    • | : Pipes output from the left command into the right command.
  • atq : Lists queued at jobs.
  • at -c <jobid> : Prints the exact script that will execute for a queued job.
    • -c : Displays job contents (environment + commands).
  • atrm <jobid> : Removes a queued job by job ID.