diff --git a/friendica-remove-old-photos-parallel.sh b/friendica-remove-old-photos-parallel.sh index 7e0272a..c49878a 100755 --- a/friendica-remove-old-photos-parallel.sh +++ b/friendica-remove-old-photos-parallel.sh @@ -10,10 +10,13 @@ loop() { #Parse each file in folder folderescaped=${folder////\\/} ky=$(echo "${y}" | sed -e "s/${folderescaped}/https:\/\/${url}/g" -e "s/-[0-9]*\..*\$//g") - f=$(sudo mariadb "${db}" -N -B -q -e "select photo from contact where photo like '${ky}%' limit 1") + f=$(mariadb "${db}" -N -B -q -e "select photo from contact where photo like '${ky}%' limit 1") if [[ $? -eq 0 && -z ${f} && -f ${y} ]]; then - ls -lh "${y}" - sudo rm -rf "${y}" + ( ls -lh "${y}" && rm -rf "${y}" ) & + if [[ $(jobs -r -p | wc -l) -ge $(($(getconf _NPROCESSORS_ONLN) * 2)) ]]; then + wait -n + fi + d=$((d + 1)) fi #printf "\rPhotos: %s\tFolder %s\tEntry %s " "$d" "$n" "$m" @@ -24,12 +27,11 @@ loop() { date #Go to the Friendica installation cd "${folderavatar}" || exit -#let "indexlength=37+${#url}" -((indexlength = 49 + ${#url})) -sudo mariadb "${db}" -e "alter table contact add index if not exists photo_index (photo(${indexlength}))" +indexlength=$((49 + ${#url})) +mariadb "${db}" -e "alter table contact add index if not exists photo_index (photo(${indexlength}))" n=0 d=0 -sudo find "${folderavatar}" -depth -mindepth 1 -maxdepth 1 -type d | while read -r x; do +find "${folderavatar}" -depth -mindepth 1 -maxdepth 1 -type d | while read -r x; do n=$((n + 1)) #If the directory still exists if [[ -d "${x}" ]]; then @@ -43,10 +45,10 @@ sudo find "${folderavatar}" -depth -mindepth 1 -maxdepth 1 -type d | while read if [[ $(jobs -r -p | wc -l) -ge $(($(getconf _NPROCESSORS_ONLN) * 2)) ]]; then wait -n fi - #done < <(sudo find "${x}" -type f -mtime -8) - done < <(sudo find "${x}" -type f) + #done < <(find "${x}" -type f -mtime -8) + done < <(find "${x}" -type f) fi fi done -sudo mariadb "${db}" -e "alter table contact drop index photo_index" +mariadb "${db}" -e "alter table contact drop index photo_index" date