summaryrefslogtreecommitdiff
path: root/custom/uucp-mediaserver/scripts/queuestatus
blob: babacfeac488e2b489bb49e7a14bdb14e548f779 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!@zsh@/bin/zsh

typeset -a queue
queue=()

suffix=${${0:t}##*.}
uucpsize() {
    command queuesize.${suffix} ${@}
}
mediaspace() {
    cat @queueDir@/${suffix}.space
}
queuesize() {
    local sum=0
    for file (${queue}); do
        local size=$(stat -c "%s" "${file}") || continue
        sum=$((sum + size))
    done
    printf "%d" ${sum}
}

queueTxt=$(grep -vE '^\s*$' @queueDir@/${suffix}.queue)
queue=(${(f)queueTxt})

printf "Space: %s\n  Reported: %s\n  UUCP queue size: %s\n" \
       $(numfmt --to=iec-i --suffix=B -- $(($(mediaspace) - $(uucpsize)))) \
       $(mediaspace | numfmt --to=iec-i --suffix=B) \
       $(uucpsize | numfmt --to=iec-i --suffix=B)

printf "Queue: %d\n  Size: %s\n" \
       ${#queue} \
       $(queuesize | numfmt --to=iec-i --suffix=B)

printf "\n"

for file (${queue}); do
    size() {
        stat -c "%s" "${file}" | numfmt --to=iec-i --suffix=B
    }
    printf "%6s %s\n" $(size || printf "N/A") ${file:t}
done