at jobs: キュー ID および作業ファイル

at jobs: キュー ID および作業ファイル
root@calleva:/var/spool/cron/atjobs# echo "sleep 3000" | at 20:58
warning: commands will be executed using /bin/sh
job 161 at Sat Jun  3 20:58:00 2023

root@calleva:/var/spool/cron/atjobs# ls
a000a101acba0e

root@calleva:/var/spool/cron/atjobs# cat a000a101acba0e
#!/bin/sh
# atrun uid=0 gid=0
# mail root 0
umask 22
LANGUAGE=en_GB:en; export LANGUAGE
PWD=/var/spool/cron/atjobs; export PWD
LOGNAME=root; export LOGNAME
XDG_SESSION_TYPE=tty; export XDG_SESSION_TYPE
MOTD_SHOWN=pam; export MOTD_SHOWN
HOME=/root; export HOME
LANG=en_GB.UTF-8; export LANG
SSH_CONNECTION=192.168.0.12\ 60848\ 192.168.0.113\ 22; export SSH_CONNECTION
XDG_SESSION_CLASS=user; export XDG_SESSION_CLASS
USER=root; export USER
SHLVL=0; export SHLVL
XDG_SESSION_ID=1202; export XDG_SESSION_ID
XDG_RUNTIME_DIR=/run/user/0; export XDG_RUNTIME_DIR
SSH_CLIENT=192.168.0.12\ 60848\ 22; export SSH_CLIENT
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.dotnet/tools:/root/bin:/opt/mssql-tools/bin:/usr/games; export PATH
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/0/bus; export DBUS_SESSION_BUS_ADDRESS
SSH_TTY=/dev/pts/5; export SSH_TTY
OLDPWD=/root; export OLDPWD
cd /var/spool/cron/atjobs || {
         echo 'Execution directory inaccessible' >&2
         exit 1
}
sleep 3000


root@calleva:/var/spool/cron/atjobs# atq
161     Sat Jun  3 20:58:00 2023 a root

root@calleva:/var/spool/cron/atjobs#

a000a101acba0eファイルがキューエントリに対応するかどうかを知る方法はありますか161

答え1

全体を見ながら源泉我々は発見する

writefile(time_t runtimer, char queue)
...
(void)snprintf(ppos, sizeof(atfile) - (ppos - atfile),
       "%c%5lx%8lx", queue, jobno, (unsigned long) (runtimer / 60));

だからa000a101acba0e

  • a「へ」について
  • 000a116進数でジョブ番号161。確認してくださいecho $((16#00a1))
  • 01acba0eエポック以降のジョブを実行する時間(分)。で確認してくださいecho "obase=16;$(date +%s)/60" | bc

答え2

#!/bin/sh

for f in /var/spool/cron/atjobs/*; do
        fn=$(basename $f)

        jobHex=$(echo "$fn" | cut -c2-6 | tr "a-z" "A-Z")
        jobDec=$(echo "ibase=16;$jobHex" | bc)

        tHex=$(echo "$fn" | cut -c7-14 | tr "a-z" "A-Z")
        tDec=$(echo "ibase=16;$tHex * 3C" | bc) # 0x3C is 60.
        tT=$(date --date="@$tDec" +%Y-%m-%dT%H-%M)

        cmd=$(tail -2 $f | head -1)

        echo "Job $job at $tT is $cmd"
done

関連情報