How to View and Inspect Contents of Scheduled ‘at’ Jobs in Linux


2 views

The at command in Linux allows users to schedule one-time tasks to be executed at a specified time. While atq shows the queue of pending jobs, many administrators need to inspect the actual commands being scheduled.

Here are the most reliable ways to examine scheduled at jobs:

# List jobs with their IDs
atq

# View contents of a specific job (replace XX with job ID)
at -c XX

For systems where at -c isn't available, you can examine the spool files directly:

# Locate and view a specific job file
sudo ls -l /var/spool/cron/atjobs/
sudo cat /var/spool/cron/atjobs/aXXXXXX

Let's walk through a complete example:

# Schedule a test job
echo "echo 'Hello World' > /tmp/at_test" | at now + 1 minute

# View the queue
atq

# Sample output:
# 10      Mon Sep 12 14:30:00 2022 a username

# Inspect job contents
at -c 10 | less

# Look for the actual command in the output
  • Job files in /var/spool/cron/atjobs/ are binary formatted
  • The at -c command shows environment setup and cleanup code
  • You'll need root privileges to view other users' jobs

For systems using atrun, you can check the log:

grep "atrun" /var/log/syslog

The at command in Linux allows users to schedule one-time tasks to be executed at a specified time. While atq shows the queue of pending jobs, many administrators need to inspect the actual commands being scheduled.

The most straightforward way to view job contents is using the -c flag with the job ID:

at -c job_id

For example, to view job #5:

at -c 5

This displays the complete environment and commands that will be executed.

For system-level inspection, you can examine the raw files in /var/spool/cron/atjobs:

sudo cat /var/spool/cron/atjobs/a00005

Replace "a00005" with your actual job filename (prefixed with 'a' and zero-padded to 5 digits).

Here's a bash script that lists all pending jobs with their contents:

#!/bin/bash
for job in $(atq | awk '{print $1}'); do
  echo "=== Job $job ==="
  at -c $job
  echo ""
done

To extract just the commands without environment variables:

at -c job_id | grep -v '^#' | grep -v '^$'

Remember that viewing other users' jobs typically requires root privileges. Always follow your organization's security policies when inspecting scheduled jobs.