如何重新安排 at 作业以更早运行?

如何重新安排 at 作业以更早运行?

假设我安排了一个at作业在 3 小时后运行:

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

但过了 1 小时后我改变了主意,然后需要立即#9从队列中运行该特定作业a,即比计划运行的时间早 2 小时。

我该怎么做?

我知道我可以将作业命令打印到stdout,将其复制并粘贴到命令行,手动运行它,然后删除作业#9

$ at -c 9
command
$ command
$ atrm 9

但这相当于跑步其他工作,不是#9来自队列a

答案1

有两种可能:

答案2

根据已接受的答案,这是一个方便的脚本(我称之为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

相关内容