From d6e51a9c27b91ff6e8a95f0940b3b9ae898043b5 Mon Sep 17 00:00:00 2001 From: toast-ts <96593068+toast-ts@users.noreply.github.com> Date: Mon, 22 Jan 2024 17:04:54 +1100 Subject: [PATCH] Fix broken pipe --- ufwReject.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ufwReject.sh b/ufwReject.sh index 40e809a..d148a0a 100755 --- a/ufwReject.sh +++ b/ufwReject.sh @@ -14,12 +14,15 @@ dmesg | grep 'SRC=' | awk -F'SRC=' '{ print $2 }' | awk '{ print $1 }' | sort | # Initialize a counter for new IPs new_ips=0 +# Store the output of ufw status in a variable +ufw_status=$(ufw status) + # Populate the UFW reject rule with the IP addresses collected from the kernel log while IFS= read -r ip do ip_prefix="${ip%.*}" # Check if the IP is already in the UFW rules - if ! ufw status | grep -q "$ip" && [ "$ip_prefix" != "${TOAST_IP%.*}" ] + if ! echo "$ufw_status" | grep -q "$ip" && [ "$ip_prefix" != "${TOAST_IP%.*}" ] then ufw reject from $ip # Increment the counter