Posts Tagged ‘bash’

DNS Offenders

Thursday, March 12th, 2009

I noticed some interesting DNS error messages in my syslog and wanted to find out who the biggest offenders were.

sudo grep named /var/log/syslog | awk -F”: ” ‘{print $3}’ | grep ‘^[0-9]‘ | sort > dns_harass_ip.txt
for ip in $(uniq dns_harass_ip.txt); do echo -n `grep -c “$ip” dns_harass_ip.txt` && echo ” — $ip”; done | sort -nr

Let’s break these down and explain.

  1. sudo grep named /var/log/syslog: Show any syslog messages from named
  2. awk -F”: ” ‘{print $3}’: Using the characters colon-space as a delimiter, print the third field (IP)
  3. grep ‘^[0-9]‘: Only show fields that start with a number (IP)
  4. sort > dns_harass_ip.txt: Sort and dump the IP addresses
  5. for ip in $(uniq dns_harass_ip.txt); do: For each unique IP address
    1. echo -n `grep -c “$ip” dns_harass_ip.txt`: Print, without a newline, the number of occurrences
    2. echo ” — $ip”: Then print, with a newline, the actual IP address
  6. sort -nr: Sort by numeric value in reverse, or descending, order

That’s all.  From there you can firewall any outstanding offenders or select a different course of action.

Spaces? In MY SCP?!

Saturday, January 17th, 2009

Here is how to deal with space(s) in a remote source file with SCP:

scp user@hostname:”‘/path/to/my file name/which has spaces’” /local/path

Double quote, apostrophe.  It’s more likely than you think.