3 UNIX / Linux atq Command Examples to Display Pending at Jobs

atq command is part of the at package, which is used to schedule jobs in the background.

atq command will display all pending jobs that still needs to be executed.

Each and every line in the atq output will have the following fields

  • Job Number – The job number
  • Date – The date when this specific job will be executed
  • Hour – The exact hour when this specific job number will be executed
  • Queue – The name of the queue
  • Username – The username who scheduled this particular job

1. Basic Usage

For example, let us assume that we’ve scheduled a at job which will execute all the script mentioned in the myjobs.txt file 1 hour from now.

# at -f myjobs.txt now + 1 hour
job 3 at 2014-03-10 10:10

When you execute the at command, it will display all the pending jobs as shown below. Currently there are two jobs waiting to be executed.

# atq
2       2014-03-10 10:09 a root
3       2014-03-10 10:10 a root

2. Specific Queue

By Default the at command schedules the job using “a” queue. As you see in the above output, the 4th column shows the value of “a” indicating the default queue.

However you can change the queue name. Valid queue names are from a through z. Queue name has to be a single letter.

In the following example, let us run a new at job using queue “z”.

# at -q z -f /root/myjobs.txt now + 1 hour
job 4 at 2014-03-10 10:13

Now when you execute the atq command you’ll see this new job number 4, which has “z” in the 4th column of the output indicating that this particular job is running in the “z” queue.

# atq
4       2014-03-10 10:13 z root
2       2014-03-10 10:09 a root
3       2014-03-10 10:10 a root

If you like to view only the jobs that belongs to a specific queue, use the -q option.

The following command displays only the at jobs that belongs to the default queue a.

# atq -q a
2       2014-03-10 10:09 a root
3       2014-03-10 10:10 a root

The following command displays only the at jobs that belongs to the queue z.

# atq -q z
4       2014-03-10 10:13 z root

Note: If you see = in the queue name for a particular job in the atq output, it indicates that particular job is currently running.

3. Display User’s Job

Let us assume that user john is execute the following at job.

$ at -f john-jobs.txt now + 1 hour
job 5 at 2014-03-10 10:14

When John executes the atq command, he’ll see only his job as shown below.

$ atq
5       2014-03-10 10:14 a john

However when root executes the command, all at jobs will be listed. i.e including root at jobs, and all other user’s at jobs as shown below.

# atq
4       2014-03-10 10:13 z root
5       2014-03-10 10:14 a john
2       2014-03-10 10:09 a root
3       2014-03-10 10:10 a root