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对于“在”
  • 000a1十六进制的作业编号 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

相关内容