msgbartop
MAC OS X, Linux, Windows and other IT Tips and Tricks
msgbarbottom

05 Nov 16 Displaying the list of all ‘at’ jobs and their respective commands

Introduction:
The command atq gives me the list of at jobs waiting to be executed and their execution times. Each line starting with the job number.
The command at -c JobNumber gives me the content of the job including the environment variables.
What I wanted is a command that would give me the list of the jobs (just like the command atq) but expanded so that each job line is followed by the commands that will be executed, excluding their environment variables. eg.
34 Tue Jan 17 10:22:00 2017 a root
Commands
35 Tue Jan 24 17:50:00 2017 a root
Commands
28 Tue Dec 13 23:00:00 2016 a root
Commands
24 Mon Nov 14 20:27:00 2016 a root
Commands
31 Sun Jan 15 00:21:00 2017 a root
Commands

Humm… could not find such command to display this. So I created this bash script which does the job:

#!/bin/bash
# Description: Displays all 'at' jobs and their respective commands
# Syntax: atlist.sh
# Changes: 05.11.2016 First implementation
########################################################################
# Get the short jobs list and expand from there
atq | while read line ; do
jobnr=$(echo $line | awk '{print $1}')
echo $line
# Pickup all the command lines after first line matching '}'.
# This excludes all the environment variables and the at exit line.
# Exclude the matching '}' line and empty lines
# Add an offset of 8 chars to each command line.
at -c $jobnr | sed -e '1,/^\}/d' -e '/^$/d' -e 's/^/ /'
done

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: