|
|
|
|
@ -20,16 +20,23 @@ script_init osh-remove-empty-folders config_optional check_secure_lax
|
|
|
|
|
|
|
|
|
|
# first, we list all the directories to get a count
|
|
|
|
|
_log "Counting the number of directories before the cleanup..."
|
|
|
|
|
nbdirs_before=$(find /home/ -mindepth 3 -maxdepth 3 -type d -regextype egrep -regex '^/home/[^/]+/ttyrec/[0-9.]+$' -print | wc -l)
|
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
|
nbdirs_before=$(find $FIND_EGREP_POSITIONAL_BEFORE /home/ -mindepth 3 -maxdepth 3 -type d \
|
|
|
|
|
$FIND_EGREP_POSITIONAL_AFTER '^/home/[^/]+/ttyrec/[0-9.]+$' -print | wc -l)
|
|
|
|
|
|
|
|
|
|
_log "We have $nbdirs_before directories, removing empty ones..."
|
|
|
|
|
# then we pass them all through rmdir, it'll just fail on non-empty ones.
|
|
|
|
|
# this is (way) faster than trying to be smart and listing each and every directory's contents first.
|
|
|
|
|
find /home/ -mindepth 3 -maxdepth 3 -type d -mtime +$MTIME_DAYS -regextype egrep -regex '^/home/[^/]+/ttyrec/[0-9.]+$' -print0 | xargs -r0 rmdir -- 2>/dev/null
|
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
|
find $FIND_EGREP_POSITIONAL_BEFORE /home/ -mindepth 3 -maxdepth 3 -type d \
|
|
|
|
|
-mtime +$MTIME_DAYS $FIND_EGREP_POSITIONAL_AFTER -regex '^/home/[^/]+/ttyrec/[0-9.]+$' -print0 | \
|
|
|
|
|
xargs -r0 rmdir -- 2>/dev/null
|
|
|
|
|
|
|
|
|
|
# finally, see how many directories remain
|
|
|
|
|
_log "Counting the number of directories after the cleanup..."
|
|
|
|
|
nbdirs_after=$(find /home/ -mindepth 3 -maxdepth 3 -type d -regextype egrep -regex '^/home/[^/]+/ttyrec/[0-9.]+$' -print | wc -l)
|
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
|
nbdirs_after=$(find $FIND_EGREP_POSITIONAL_BEFORE /home/ -mindepth 3 -maxdepth 3 -type d \
|
|
|
|
|
$FIND_EGREP_POSITIONAL_AFTER -regex '^/home/[^/]+/ttyrec/[0-9.]+$' -print | wc -l)
|
|
|
|
|
|
|
|
|
|
_log "Finally deleted $((nbdirs_before - nbdirs_after)) directories in this run"
|
|
|
|
|
|
|
|
|
|
|