How to use the command 'atq' (with examples)
The ‘atq’ command is used to display the jobs that have been scheduled using the ‘at’ or ‘batch’ commands. It allows users to see their own scheduled jobs or view all jobs, depending on the options used. This article provides examples of different use cases of the ‘atq’ command.
Use case 1: Show the current user’s scheduled jobs
Code:
atq
Motivation: This use case is useful when you want to check the jobs that you have scheduled to run at a specified time using the ‘at’ command. By using ‘atq’, you can quickly view your scheduled jobs without having to remember the exact time or date.
Explanation: The ‘atq’ command without any options will display the jobs scheduled by the current user. It queries the job queue and retrieves the jobs that are waiting to be executed.
Example output:
28 Sat Feb 20 15:00:00 2021 a ec2-user
29 Sat Feb 20 16:00:00 2021 a ec2-user
In this example, the output shows two scheduled jobs with IDs 28 and 29. The jobs are scheduled to run on Saturday, February 20th, 2021, at 15:00:00 and 16:00:00, respectively. The jobs are scheduled by the user ’ec2-user’.
Use case 2: Show jobs from queue named ‘a’
Code:
atq -q a
Motivation: This use case is helpful when there are multiple queues, each with different types of jobs. By specifying the queue name, you can filter the output to display only the jobs from that specific queue.
Explanation: The ‘-q’ option followed by the queue name allows you to filter the jobs based on the specified queue. In this example, ‘-q a’ is used to show only the jobs from the queue named ‘a’.
Example output:
28 Sat Feb 20 15:00:00 2021 a ec2-user
29 Sat Feb 20 16:00:00 2021 a ec2-user
In this example, the output is the same as the previous use case because all the jobs displayed belong to the queue ‘a’.
Use case 3: Show jobs of all users (run as superuser)
Code:
sudo atq
Motivation: This use case is useful for system administrators who need to monitor and manage jobs scheduled by all users on the system. By running the ‘atq’ command with superuser privileges, all the scheduled jobs from all users can be viewed.
Explanation: The ‘sudo’ command is used to run the ‘atq’ command with superuser privileges, giving the user access to jobs scheduled by all users on the system. This allows system administrators to have a comprehensive view of all scheduled tasks.
Example output:
28 Sat Feb 20 15:00:00 2021 a ec2-user
29 Sat Feb 20 16:00:00 2021 a ec2-user
34 Sat Feb 20 08:00:00 2021 a root
35 Sat Feb 20 09:00:00 2021 a root
In this example, the output includes the jobs from both the current user (’ec2-user’) and the root user (‘root’). The jobs scheduled by the root user have IDs 34 and 35, and their execution times are on Saturday, February 20th, 2021, at 08:00:00 and 09:00:00, respectively.
Conclusion:
The ‘atq’ command is a helpful tool for managing and monitoring scheduled jobs. It allows users to quickly view their own scheduled jobs or retrieve information about jobs from specific queues or all users on the system. By understanding the different use cases of the ‘atq’ command, users can effectively utilize it to manage their scheduled tasks.