feat: Improve the output method for several scripts

This commit is contained in:
Carlos Solís 2025-03-06 09:31:04 -06:00
parent e3d167b7de
commit 1162155b25
3 changed files with 32 additions and 14 deletions

View file

@ -10,7 +10,7 @@ else
fi fi
intense_optimizations=${1:-"0"} intense_optimizations=${1:-"0"}
db="friendica" db="friendica"
period="3 MONTH" period="1 MONTH"
tmpfile=/tmp/friendica-delete-old-users.csv tmpfile=/tmp/friendica-delete-old-users.csv
url=friendica.example.net url=friendica.example.net
avatarfolder=/var/www/friendica/avatar avatarfolder=/var/www/friendica/avatar
@ -71,22 +71,27 @@ loop() {
echo "${picturecount}" "${postthreadcount} ${postthreadusercount} ${postusercount} ${posttagcount} ${postcontentcount} ${postcount} ${photocount} ${contactcount} ${apcontactcount} ${diasporacontactcount}" >"${tmpfile}" echo "${picturecount}" "${postthreadcount} ${postthreadusercount} ${postusercount} ${posttagcount} ${postcontentcount} ${postcount} ${photocount} ${contactcount} ${apcontactcount} ${diasporacontactcount}" >"${tmpfile}"
#Previous line clearance #Previous line clearance
#Measure length of string, blank only the excess #Measure length of string, blank only the excess
#Since this string is panned to both sides, we will need to account for two lengths
final_string_length_left="${#response_left}" final_string_length_left="${#response_left}"
final_string_length_right="${#response}" final_string_length_right="${#response}"
final_string_length=$((final_string_length_left + final_string_length_right)) final_string_length=$((final_string_length_left + final_string_length_right))
#The string that will be used to insert the blanks
blank_string="" blank_string=""
columns_length="${COLUMNS}" columns_length="${COLUMNS}"
#Account for the case where the string is more than a terminal line long
while [[ "${final_string_length}" -gt "${columns_length}" ]]; do while [[ "${final_string_length}" -gt "${columns_length}" ]]; do
columns_length=$((columns_length + COLUMNS)) columns_length=$((columns_length + COLUMNS))
done done
blank_string_length=$((columns_length - final_string_length)) blank_string_length=$((columns_length - final_string_length))
#Add enough blank spaces to fill the rest of the line
for ((count = 0; count < "${blank_string_length}"; count++)); do for ((count = 0; count < "${blank_string_length}"; count++)); do
blank_string=$(printf "%s " "${blank_string}") blank_string=$(printf "%s " "${blank_string}")
done done
response=$(printf "%s%s%s" "${response_left}" "${blank_string}" "${response}") #Add backspaces to align the next output
for ((count = 0; count < "${final_string_length}"; count++)); do for ((count = 0; count < $((final_string_length + blank_string_length)); count++)); do
response=$(printf "%s\b" "${response}") response_left=$(printf "\b%s" "${response_left}")
done done
response=$(printf "%s%s%s" "${response_left}" "${blank_string}" "${response}")
printf "%s\r" "${response}" printf "%s\r" "${response}"
} }
@ -106,12 +111,12 @@ if [[ -n $(type curl) && -n "${dbengine}" && -n $(type "${dbengine}") && -n $(ty
c.\`contact-type\` != 4 and not pending and \`last-discovery\` < CURDATE() - INTERVAL ${period} and \`last-item\` < CURDATE() - INTERVAL ${period}" | c.\`contact-type\` != 4 and not pending and \`last-discovery\` < CURDATE() - INTERVAL ${period} and \`last-item\` < CURDATE() - INTERVAL ${period}" |
while read -r id nick baseurl lastitem; do while read -r id nick baseurl lastitem; do
loop "${id}" "${nick}" "${baseurl}" & loop "${id}" "${nick}" "${baseurl}" &
if [[ $(jobs -r -p | wc -l) -ge $(($(getconf _NPROCESSORS_ONLN) / 1)) ]]; then if [[ $(jobs -r -p | wc -l) -ge $(($(getconf _NPROCESSORS_ONLN) * 2)) ]]; then
wait -n wait -n
fi fi
done done
printf "\r\n"
wait wait
printf "\n\r"
"${dbengine}" "${db}" -N -B -q -e "alter table \`post-thread\` auto_increment = 1; \ "${dbengine}" "${db}" -N -B -q -e "alter table \`post-thread\` auto_increment = 1; \
alter table \`post-thread-user\` auto_increment = 1; \ alter table \`post-thread-user\` auto_increment = 1; \
alter table \`post-user\` auto_increment = 1; \ alter table \`post-user\` auto_increment = 1; \

View file

@ -99,22 +99,27 @@ loop_3() {
echo "${picturecount}" "${postthreadcount} ${postthreadusercount} ${postusercount} ${posttagcount} ${postcontentcount} ${postcount} ${photocount} ${contactcount} ${apcontactcount} ${diasporacontactcount}" >"${usrfile}" echo "${picturecount}" "${postthreadcount} ${postthreadusercount} ${postusercount} ${posttagcount} ${postcontentcount} ${postcount} ${photocount} ${contactcount} ${apcontactcount} ${diasporacontactcount}" >"${usrfile}"
#Previous line clearance #Previous line clearance
#Measure length of string, blank only the excess #Measure length of string, blank only the excess
#Since this string is panned to both sides, we will need to account for two lengths
final_string_length_left="${#response_left}" final_string_length_left="${#response_left}"
final_string_length_right="${#response}" final_string_length_right="${#response}"
final_string_length=$((final_string_length_left + final_string_length_right)) final_string_length=$((final_string_length_left + final_string_length_right))
#The string that will be used to insert the blanks
blank_string="" blank_string=""
columns_length="${COLUMNS}" columns_length="${COLUMNS}"
#Account for the case where the string is more than a terminal line long
while [[ "${final_string_length}" -gt "${columns_length}" ]]; do while [[ "${final_string_length}" -gt "${columns_length}" ]]; do
columns_length=$((columns_length + COLUMNS)) columns_length=$((columns_length + COLUMNS))
done done
blank_string_length=$((columns_length - final_string_length)) blank_string_length=$((columns_length - final_string_length))
#Add enough blank spaces to fill the rest of the line
for ((count = 0; count < "${blank_string_length}"; count++)); do for ((count = 0; count < "${blank_string_length}"; count++)); do
blank_string=$(printf "%s " "${blank_string}") blank_string=$(printf "%s " "${blank_string}")
done done
response=$(printf "%s%s%s" "${response_left}" "${blank_string}" "${response}") #Add backspaces to align the next output
for ((count = 0; count < "${final_string_length}"; count++)); do for ((count = 0; count < $((final_string_length + blank_string_length)); count++)); do
response=$(printf "%s\b" "${response}") response_left=$(printf "\b%s" "${response_left}")
done done
response=$(printf "%s%s%s" "${response_left}" "${blank_string}" "${response}")
printf "%s\r" "${response}" printf "%s\r" "${response}"
} }
@ -166,7 +171,7 @@ if [[ -n $(type curl) && -n "${dbengine}" && -n $(type "${dbengine}") && -n $(ty
fi fi
wait wait
done <"${idsdownfile}" done <"${idsdownfile}"
printf "\r\n" printf "\n\r"
rm "${tmpfile}" 2>/dev/null rm "${tmpfile}" 2>/dev/null
rm "${idsdownfile}" 2>/dev/null rm "${idsdownfile}" 2>/dev/null
rm "${usrfile}" 2>/dev/null rm "${usrfile}" 2>/dev/null

View file

@ -303,15 +303,23 @@ loop() {
final_string_length="${#final_string}" final_string_length="${#final_string}"
#Previous line clearance #Previous line clearance
#Measure length of string, blank only the excess #Measure length of string, blank only the excess
#The string that will be used to insert the blanks
blank_string="" blank_string=""
blank_string_length=$((COLUMNS - final_string_length)) columns_length="${COLUMNS}"
#Account for the case where the string is more than a terminal line long
while [[ "${final_string_length}" -gt "${columns_length}" ]]; do
columns_length=$((columns_length + COLUMNS))
done
blank_string_length=$((columns_length - final_string_length))
#Add enough blank spaces to fill the rest of the line
for ((count = 0; count < "${blank_string_length}"; count++)); do for ((count = 0; count < "${blank_string_length}"; count++)); do
blank_string=$(printf "%s " "${blank_string}") blank_string=$(printf "%s " "${blank_string}")
done done
final_string=$(printf "%s%s" "${final_string}" "${blank_string}") #Add backspaces to align the next output
for ((count = 0; count < "${blank_string_length}"; count++)); do for ((count = 0; count < $((final_string_length + blank_string_length)); count++)); do
final_string=$(printf "%s\b" "${final_string}") final_string=$(printf "\b%s" "${final_string}")
done done
final_string=$(printf "%s%s" "${final_string}" "${blank_string}")
#Add a new line only when necessary #Add a new line only when necessary
if [[ "${nl}" -eq 1 ]]; then if [[ "${nl}" -eq 1 ]]; then
final_string=$(printf "%s\n\r\n" "${final_string}") final_string=$(printf "%s\n\r\n" "${final_string}")