Commit 76508069 authored by Vitaly Lipatov's avatar Vitaly Lipatov

cli: count ipset entries accurately

parent 822821d4
...@@ -3,14 +3,17 @@ ...@@ -3,14 +3,17 @@
setname="eterban_1" setname="eterban_1"
setname_ipv6="eterban_1_ipv6" setname_ipv6="eterban_1_ipv6"
count_set() {
ipset list "$1" 2>/dev/null | awk '/^Number of entries:/ { print $4; found=1 } END { if (!found) print 0 }'
}
command="$1" command="$1"
[ -n "$command" ] && shift [ -n "$command" ] && shift
if [ "$command" = "count" ] ; then if [ "$command" = "count" ] ; then
echo "Count of banned:" echo "Count of banned:"
# TODO: some quiet to ignore headers echo "$setname: $(count_set "$setname")"
echo "$setname: $(ipset list $setname | wc -l)" echo "$setname_ipv6: $(count_set "$setname_ipv6")"
echo "$setname_ipv6: $(ipset list $setname_ipv6 | wc -l)"
exit exit
fi fi
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment