logrotate с параметром only size не вращается. Это внутри док-контейнера Alpine

Su script parece no usar su primer argumento. Se pasa a la función Iteratey nunca se vuelve a ver.

Pero el verdadero problema es que ejecuta diffen cada combinación de dos archivos y luego observa el tamaño de la diferencia. El tamaño de la diferencia no será -cero para archivos que sean diferentes. Por lo tanto, su secuencia de comandos informa Yespara cada combinación de archivos que son diferentes , no iguales.

También ejecuta innecesariamente la diferencia entre el archivo Ay Bdos veces(Afrente a By luego Bfrente aA). Puede solucionar esto generando la lista de archivos solo una vez y luego iterando sobre eso.

Guión alternativo:

#!/bin/sh

if [ ! -d "$1" ]; then
    printf 'Usage: %s directory\n' "$0" >&2
    exit 1
fi

# set positional parameters to the list of files in the given directory
set -- "$1"/*

# while there's still files to process...
while [ "$#" -gt 0 ]; do
    # skip over non-regular files
    if [ ! -f "$1" ]; then
        shift
        continue
    fi

    # now process the first item in the list against the other ones
    item=$1

    # shift off the first item from the list
    shift

    # loop over the remaining items...
    for name do
        # we're still not interested in non-regular files
        [ ! -f "$name" ] && continue

        # if they are the same, report this
        if cmp -s "$item" "$name"; then
            printf '%s and %s has same content\n' "$item" "$name"
        fi
    done
done

Aún puedes tener tus dos funciones si lo deseas:

#!/bin/sh

if [ ! -d "$1" ]; then
    printf 'Usage: %s directory\n' "$0" >&2
    exit 1
fi

check () {
    # now process the first item in the list against the other ones
    item=$1

    # shift off the first item from the list
    shift

    # loop over the remaining items...
    for name do
        # we're still not interested in non-regular files
        [ ! -f "$name" ] && continue

        # if they are the same, report this
        if cmp -s "$item" "$name"; then
            printf '%s and %s has same content\n' "$item" "$name"
        fi
    done
}

iterate () {
    # set positional parameters to the list of files in the given directory
    set -- "$1"/*

    # while there's still files to process...
    while [ "$#" -gt 0 ]; do
        # only process regular files
        if [ -f "$1" ]; then
            check "$@" # checks the first item against the rest
        fi
        shift # get rid of the first item
    done
}

iterate "$1"

Observe cómo no permitimos que la función checkgenere su propia lista de archivos. En su lugar, le pasamos la lista de archivos.

Para los vagos:

fdupes -1 /some/directory
2
24.06.2019, 14:19
2 ответа

В Alpine Linux cron не запускается по умолчанию. Следовательно, задания в любой папке не будут выполняться. Решение состояло в том, чтобы запустить cron сcrond

1
27.01.2020, 22:16

Судя по файлу logrotate.status, который вы включили, последняя ротация журналов происходила в 11 :00, а из списка каталогов видно, что после этого файлы были обновлены.

Возможно, это означает, что задания logrotateвыполняются ежечасно. Журналы должны меняться при повторном запуске задания ротации журналов или при его запуске вручную.

1
27.01.2020, 22:16

Теги

Похожие вопросы