4

Suppose I had scheduled an at job to run 3 hours later:

$ echo command | at now +3 hours
$ atq
9     Mon Dec  5 14:00:00 2016 a nr

but having passed 1 hour I change my mind, and then need to run that specific job #9 from queue a immediately, that is, 2 hours earlier than the time at which it is scheduled to run.

How can I do it?

I know I can print the job command to stdout, copy and paste it to the command line, run it manually, and then remove job #9:

$ at -c 9
command
$ command
$ atrm 9

But this amounts to running another job, not #9 from queue a.

2
  • I think the answer is that you can't. I guess being able to reschedule a job without changing the job number isn't a very commonly requested feature. Dec 5 '16 at 23:18
  • I see. Would it be possible to reschedule it, though?
    – n.r.
    Dec 6 '16 at 1:01
6

There are two possibilities:

2
  • 2
    Thanks. Would you provide the link to the other answer, please?
    – n.r.
    Dec 21 '16 at 1:23
  • I've seen the other answer, but I really love the simplicity of this one. Thank you. Jun 17 at 19:12
0

Based on the accepted answer, here is a convenient script (I call it atmv):

#!/usr/bin/bash

# Idea taken from here:
# https://unix.stackexchange.com/a/331789/68456

set -euo pipefail

atlist() { atq | sed 's/^/  /'; }

if [ $# -lt 2 ]; then
    echo "Syntax: atmv job_num new time arguments"
    exit 1
fi

job_num="$1"
shift

if [ "$(atq | cut -f 1 | grep "$job_num" | wc -l)" != "1" ]; then
    echo "Error: There is no job with number \"$job_num\"."
    echo "Pick one of these:"
    atlist
    exit 2
fi

at -c "$job_num" | at "$@" 2> /dev/null
atrm "$job_num"
echo "Done! This is the new list of at jobs:"
atlist

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.