0

My iptables rules consist some long entries, f.e. LOG target, this is causing not very nice output when I try to monitor it with watch command.

Since I am testing on lap-top, screen is not so wide. So what I thought, is it possible to exclude the last column from display? This is some example how my rules looks like:

$IT -A tcpLog -p tcp --tcp-flags SYN,ACK SYN,ACK -m conntrack --ctstate NEW -j LOG --log-prefix "[BAD TCP]" --log-level warning -m limit --limit 10/m
$IT -A tcpLog -p tcp --tcp-flags FIN,ACK FIN -j LOG --log-prefix "[BAD TCP]" --log-level warning -m limit --limit 10/m
$IT -A tcpLog -p tcp --tcp-flags ACK,PSH PSH -j LOG --log-prefix "[BAD TCP]" --log-level warning -m limit --limit 10/m

so how would I exclude the last column, which displays in this case, log prefix and related info?

Also, I monitor it like watch -n 1 iptables -L -nv Thanks

0

Here is how to exclude the last column of an output:

my_command | awk '{ $NF="" } 1'

Personally, I would prefer to truncate the output to a specific width, with one of the following commands:

my_command | pr -t -W "$COLUMNS"
my_command | cut -c "-$COLUMNS"

Here COLUMNS is a variable set by bash to the width of your terminal when the option checkwinsize is on (shopt -s checkwinsize). You can of course use any number of your choice instead.

  • my_command | pr -t -W "$COLUMNS" doing a job for me. Thanks a lot! – fugitive Dec 23 '16 at 15:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.