It's reading presumably IPs from the /tmp/voipbl.txt
file and then creating a shell if construct based on them. The $1
parameter from the awk script refers to the item in the first column on each line so the string in place of 1.2.3.4/32
will be that value in each iteration.
if [ ! -z "1.2.3.4/32" -a "1.2.3.4/32" != "#" ]; then
! -z "1.2.3.4/32"
- Is checking that "1.2.3.4/32"
is not null. -z
checks if the string is zero but the !
negates that. This could and probably should be replaced with -n
which just checks for not-null
"1.2.3.4/32" != "#"
- Is checking that "1.2.3.4/32"
is not equal to #
which I guess is something that could appear in your file.
The -a
operator means and. So it's checking that the string is not null AND that it does not equal #
.
If these conditions are met, the following will be executed:
/usr/sbin/ipset -A voipbl_temp "1.2.3.4/32"
To understand this better, try running the awk command on a file with the following contents:
1.2.3.4/32
# 3.4.5.6/32
If you now run your awk command on that file, you get:
$ awk '{ print "if [ ! -z \""$1"\" -a \""$1"\" != \"#\" ]; then /usr/sbin/ipset -A voipbl_temp \""$1"\" ;fi;"}' file
if [ ! -z "1.2.3.4/32" -a "1.2.3.4/32" != "#" ]; then /usr/sbin/ipset -A voipbl_temp "1.2.3.4/32" ;fi;
if [ ! -z "" -a "" != "#" ]; then /usr/sbin/ipset -A voipbl_temp "" ;fi;
if [ ! -z "#" -a "#" != "#" ]; then /usr/sbin/ipset -A voipbl_temp "#" ;fi;
The tests ensure that the /usr/sbin/ipset
will only be run on the first line, with 1.2.3.4/32
and not on the other two.
man test
to see what the brackets (and the-a
) mean. – steeldriver Jun 6 '19 at 17:04