bash function inside of an awk statement...
So I created a function called IPT ...
function IPT {
cat /etc/hosts.deny|\
awk '!/#/ &&
/./ &&
! a[$0]++
{print "iptables -A INPUT -s "$1" -i eth0 -d xxx.xxx.xxx.xxx -p TCP --dport 22 -j REJECT"}'|\
awk '/iptables/ && !/#/ && !/-s -i/'|sh
}
Anyway... What I need to do is this... (it's scripted)
ifaddr=$( ifconfig -a|awk '/inet/ && !/inet6/ && !/127.0/ && !/192.268/{print $2}' )
function IPT {
cat /etc/hosts.deny|\
awk '!/#/ &&
/./ &&
! a[$0]++
{print "iptables -A INPUT -s "$1" -i eth0 -d $ifaddr -p TCP --dport 22 -j REJECT"}'|\
awk '/iptables/ && !/#/ && !/-s -i/'|sh
}
For those who don't understand what's going... (UUOC police don't arrest me now!)
!/#/ && ... Ignore comments
/./ && ... grep decimal points
! a[$0]++ ... return uniq values..
then print it
{print "iptables -A INPUT -s "$1" -i eth0 -d xxx.xxx.xxx.xxx -p TCP --dport 22 -j REJECT"}'|\
Here I had to re-pipe it to awk. For some reason it still gave me comments... Not a problem
awk '/iptables/ && !/#/ && !/-s -i/'|sh
re-ignore comments, and the line "-s -i" then send it through to be processed...
perl -e 'print $i=pack(c5,(40*2),sqrt(7600),(unpack(c,Q)-3+1+3+3-7),oct(104),10,oct(101));'
So I created a function called IPT ...
function IPT {
cat /etc/hosts.deny|\
awk '!/#/ &&
/./ &&
! a[$0]++
{print "iptables -A INPUT -s "$1" -i eth0 -d xxx.xxx.xxx.xxx -p TCP --dport 22 -j REJECT"}'|\
awk '/iptables/ && !/#/ && !/-s -i/'|sh
}
Anyway... What I need to do is this... (it's scripted)
ifaddr=$( ifconfig -a|awk '/inet/ && !/inet6/ && !/127.0/ && !/192.268/{print $2}' )
function IPT {
cat /etc/hosts.deny|\
awk '!/#/ &&
/./ &&
! a[$0]++
{print "iptables -A INPUT -s "$1" -i eth0 -d $ifaddr -p TCP --dport 22 -j REJECT"}'|\
awk '/iptables/ && !/#/ && !/-s -i/'|sh
}
For those who don't understand what's going... (UUOC police don't arrest me now!)
!/#/ && ... Ignore comments
/./ && ... grep decimal points
! a[$0]++ ... return uniq values..
then print it
{print "iptables -A INPUT -s "$1" -i eth0 -d xxx.xxx.xxx.xxx -p TCP --dport 22 -j REJECT"}'|\
Here I had to re-pipe it to awk. For some reason it still gave me comments... Not a problem
awk '/iptables/ && !/#/ && !/-s -i/'|sh
re-ignore comments, and the line "-s -i" then send it through to be processed...
perl -e 'print $i=pack(c5,(40*2),sqrt(7600),(unpack(c,Q)-3+1+3+3-7),oct(104),10,oct(101));'