As Salaam O Alaikum,
I am working on a script to copy all the denied entries from iptables to a file such that i can have source address formated in a particular way i am doing the following but not getting the required results
#!/bin/bash
ipaddr=`iptables -L | grep DENY | awk '{print$4}'`
total=`iptables -L | grep DENY | awk '{print$4}' | wc -l`
for((i=1; i<="$total"; i++))
do
echo $ipaddr | awk '{print$(i)}'
done
exit $?
The problem lies in this line " echo $ipaddr | awk '{print$(i)}' " as i am not able to use loop in here.. if i am using {print$2} its working fine ...
I am not able to figure out the problem also I am not able to assign
var=$ipaddr | awk '{print$(i)}'
The format for out i require is some thing like this
The address block is $var for spamming reason
The 2nd address is $var for spamming reason
Your help in this will be very valuable as i am stuck with this and cant figure out the solution
Wasalaam
Abdus Samad
Shell Script help required
-
- Site Admin
- Posts: 5132
- Joined: Fri May 02, 2003 10:24 am
- Location: Karachi
- Contact:
Re:
Dear shad0w,
Salam,
Use below script.
Best Regards,
Salam,
Use below script.
Code: Select all
#!/bin/sh
IPADDR=`iptables -L -n | grep DROP | awk '{print $4}'`
LOGFILE="/root/ip.txt"
for i in $IPADDR
do
echo $i >> $LOGFILE
done
Farrukh Ahmed