23 marzo 2012

analisi di /var/spool/at

Nell'ultimo periodo lavoro con il comando AT (atd,atq) e una delle difficoltà è stata associare il job id che si ha come out di atq al nome del file presente nella directory /var/spool/at.
Esempio:
[root@ftp at]# atq
204 2012-04-15 23:00 a root
227 2012-06-18 23:00 a root
201 2012-04-02 11:00 a root
214 2012-04-12 10:00 a root
175 2013-02-06 23:00 a root
218 2012-03-29 10:00 a root
200 2012-04-12 23:00 a root
223 2012-04-19 23:00 a root
206 2012-04-09 10:00 a root
193 2012-03-23 11:00 a root
195 2012-03-26 23:00 a root
179 2013-02-07 23:00 a root
194 2012-03-26 10:00 a root
189 2012-03-23 11:00 a root
190 2012-03-26 10:00 a root
202 2012-04-05 10:00 a root


In verità la lista è molto più lunga. E nella directory di at abbiamo:
......
-rwx------. 1 root   root   3729 24 feb 11:01 a000bd0152df18
-rwx------. 1 root   root   3352 24 feb 11:01 a000be0152ef80
-rwx------. 1 root   root   2679 24 feb 11:01 a000bf0152f28c
-rwx------. 1 root   root   2632 24 feb 11:01 a000c001532acc
-rwx------. 1 root   root   3723 24 feb 12:11 a000c10152df18
-rwx------. 1 root   root   3346 24 feb 12:11 a000c20152ef80
-rwx------. 1 root   root   2675 24 feb 12:11 a000c30152f28c
-rwx------. 1 root   root   2630 24 feb 12:11 a000c401532acc
-rwx------. 1 root   root   3719  2 mar 18:55 a000c50153063c
-rwx------. 1 root   root   3341  2 mar 18:55 a000c6015316e0
-rwx------. 1 root   root   2669  2 mar 18:55 a000c7015319ec
-rwx------. 1 root   root   2625  2 mar 18:55 a000c80153522c
-rwx------. 1 root   root   3735  6 mar 16:57 a000c90153171c
-rwx------. 1 root   root   3356  6 mar 16:57 a000ca015327c0
-rwx------. 1 root   root   2693  6 mar 16:57 a000cb01532acc
-rwx------. 1 root   root   2637  6 mar 16:57 a000cc0153630c
-rwx------. 1 root   root   3734  8 mar 09:30 a000cd01532d9c
.....

Per esempio vorrei sapere il job id 194 a che job corrisponde.
Non ho trovato info relativamente ai nomi dei file relativi ai job quindi ho dovuto cercare di indovinarli.
Quello che segue è quello a cui sono arrivato.
Prendiamo come esempio il file a000ca015327c0
a0 = la queue
00ca = il job id in hex, quindi convertito --> 202
015327c0 = ore trascorse da epoch in hex. Ossia l'ora di partenza del job. Quindi: 
# converto in decimale e moltiplico per 60 (minuti) per ottenere i minuti da epoc.
# echo $((0x015327c0*0x3c))
1333612800

# poi converto epoch in un formato leggibile
# python -c "import time; print time.ctime(1333612800)"
Thu Apr  5 10:00:00 2012

In unica riga:
# A=`echo a000ca015327c0 | cut -b7-` &&  B=$((0x$A*0x3c)) && echo $B && python -c "import time;print time.ctime($B)"
1333612800
Thu Apr  5 10:00:00 2012

Per riassumere,  il file /var/spool/at/a000ca015327c0 corrisponde al job 202 che parte il 05/04/2012.
Quindi:
# atq|grep 202
202 2012-04-05 10:00 a root



Nessun commento:

Posta un commento