FIx it, use sponge.

This commit is contained in:
Manuel Friedli 2020-07-30 13:44:04 +02:00
parent 8d193c0122
commit ea0fae026a

View file

@ -183,10 +183,10 @@ netstat -nt | grep "${MY_IP}:${MY_PORT}" | tr -s '[:blank:]' | cut -d' ' -f5 \
| cut -d: -f1 | sort > "${fileraw}" | cut -d: -f1 | sort > "${fileraw}"
# Group and sort the data into the subnet-specific files. # Group and sort the data into the subnet-specific files.
uniq -c "${fileraw}" | sort -rn > "${file32}" cp "${fileraw}" "${file32}"
cut -d. -f1-3 "${fileraw}" | sort | uniq -c | sort -rn > "${file24}" cut -d. -f1-3 "${fileraw}" | sort > "${file24}"
cut -d. -f1-2 "${fileraw}" | sort | uniq -c | sort -rn > "${file16}" cut -d. -f1-2 "${fileraw}" | sort > "${file16}"
cut -d. -f1 "${fileraw}" | sort | uniq -c | sort -rn > "${file8}" cut -d. -f1 "${fileraw}" | sort > "${file8}"
function filter() { function filter() {
# list of current connections # list of current connections
@ -198,7 +198,10 @@ function filter() {
# Reject already banned addresses # Reject already banned addresses
while read -r -u3 address ; do while read -r -u3 address ; do
if [[ "${banned}" != *"${address}${ext}"* ]] ; then if [[ "${banned}" != *"${address}${ext}"* ]] ; then
echo "Considering ${address}."
echo "${address}" >> "${filtered}" echo "${address}" >> "${filtered}"
else
echo "IGNORING ${address}, already banned."
fi fi
done 3< "${file}" done 3< "${file}"
@ -211,6 +214,12 @@ filter "${file24}" "${ext24}"
filter "${file16}" "${ext16}" filter "${file16}" "${ext16}"
filter "${file8}" "${ext8}" filter "${file8}" "${ext8}"
# Determine the number of connections per address
uniq -c "${file32}" | sort -rn | sponge "${file32}"
uniq -c "${file24}" | sort -rn | sponge "${file24}"
uniq -c "${file16}" | sort -rn | sponge "${file16}"
uniq -c "${file8}" | sort -rn | sponge "${file8}"
# Determine the number of entries per file. # Determine the number of entries per file.
nlines32=$(cat "${file32}" | wc -l) nlines32=$(cat "${file32}" | wc -l)
nlines24=$(cat "${file24}" | wc -l) nlines24=$(cat "${file24}" | wc -l)