Tuesday, May 29, 2012

Virtual Host or Virtual IP dig digging

cmb@pscmbldl02:~
$ dig axfr my.domain.com | grep  dje00197.my.domain.com
dje00197.my.domain.com. 21600 IN A 10.76.40.34
djeswk03.my.domain.com. 21600 IN CNAME dje00197.my.domain.com.

cmb@pscmbldl02:~
$ dig axfr my.domain.com | grep pscmbldl02
scm.my.domain.com. 21600 IN CNAME pscmbldl02.my.domain.com.
scmblog.my.domain.com. 21600 IN CNAME pscmbldl02.my.domain.com.
pscmbldl02.my.domain.com. 21600 IN A 10.75.82.3
cmb@pscmbldl02:~
$ 

Tuesday, May 8, 2012

sed: how do I grep from line X until EOF?

If I have a rolling logfile with multiple lines per log record how do I print from line X until EOF?
computer:~ me$ sed -n "57450,\$p" pf/app/logs/server/trace.log

Wednesday, May 2, 2012

SED: print only lines between x and y...

Print only lines between certain line numbers... I'm sick of looking this up every two seconds... so I plagiarize and put it in my own collection.... which I know how to find :-)
# print section of file based on line numbers (lines 8-12, inclusive) 
sed -n '8,12p' # method 1 
sed '8,12!d' # method 2
Example that I needed this for: grepping lines 39000 - 40000 where an error was reported.
computer:tmp user$ ssh user@host 'cd  /QIBM/UserData/WebSphere/AppServer/V61/ND/profiles/dmgrapp/logs/dmgr && sed -n '39000,40000p' systemout.log'

Tuesday, May 1, 2012

A poor man's DNS resolving in a perl oneliner

Silly to record this ... but I hate spending more than 60 seconds on figuring out something I already figured out before... so here we go.... my own dns resolver..... Listing the resolving of the ip range: 10.75.19.80 until 10.75.19.95
$ perl -e 'for (80..95) { open EXEC, "( nslookup 10.75.19.$_ )|"  or die $!; @l=;chomp @l; ($x) = grep {/name/} @l if @l; printf "%3d - %s\n", $_, $x }' 

Wednesday, April 25, 2012

How do I remove filenames with dashes?

This does not work....
ITASC $ rm '-z'
rm: illegal option -- z
usage: rm [-f | -i] [-dPRrvW] file ...
       unlink file
Simple: use the /- to depict dashes:
./CustomFunctions/.classpath
./-z
tibco@pghdbeengl01:~/build
$ rm ./-*

Wednesday, April 18, 2012

Apache Log Regex for simpleminded parsing.

The common log format would be
10.75.80.77 2 - - [17/Apr/2012:08:52:32 -0400] "GET /EASE/admin/login.jsf HTTP/1.1" 302 - "-" "Mozilla/5.0"
So here the regex to parse this...
my $expression =
qr/([0-9\.]+)\s+\d*\s?\-\s\-\s\[(\d+)\/(\w{3})\/(\d{4}):(\d+):.*\s[-+]\d+\]\s\"(POST|GET)\s(.+)\sHTTP\/(\d.\d)\"\s(\d{3})\s(\d+|-)\s\"(\S+)\"\s\"(.+)\"/x;
my (
 $all,       $ip,       $dayofmonth, $month,    $year,
 $hourofday, $reqtype, $req,        $protocol, $response,
 $size,      $ref,     $agent
) = @rec = $_ =~ /($expression)/i;
Here an example of yet another parser implementation of apache logs... that greps all the POST and GET's
use Data::Dumper;
use Text::Table;

sub line {
 my $x = shift;
 $x = $x ? $x : $W;
 for ( 1 .. $x ) { print "-"; }
 print "\n";

}

BEGIN {
 our $W = 70;
 %row = ();
 print "\n\n";
 line($W);
 printf "[%-35s]\n", $ARGV[$cc];
 line($W);
 $cc++;
}
my @rec =();
my $expression =
qr/([0-9\.]+)\s+\d*\s?\-\s\-\s\[(\d+)\/(\w{3})\/(\d{4}):(\d+):.*\s[-+]\d+\]\s\"(POST|GET)\s(.+)\sHTTP\/(\d.\d)\"\s(\d{3})\s(\d+|-)\s\"(\S+)\"\s\"(.+)\"/x;
my (
 $all,       $ip,       $dayofmonth, $month,    $year,
 $hourofday, $reqtype, $req,        $protocol, $response,
 $size,      $ref,     $agent
) = @rec = $_ =~ /($expression)/i;

#print $dayofmonth, "\n";
if ($!) {
 my ($approot) = $req =~ m!^\/(\w+)\/.*$!x;
 my ($refhost) = $ref =~ m!https?\:\/\/([a-z.]+)\/.+!x;
 my $v = sprintf "%s %s, %s", $month, $dayofmonth, $year;
 $row{$response}{'byreq'}{$v}{$req}++;
 my $hkey = sprintf "%s-%s", $approot, $refhost;
 my $dkey = sprintf "%s-%s", $hourofday,$hkey;
 #print Dumper(\@rec);

 #die "deeeee", $v;
 $row{$response}{'byreqref'}{$v}{$req}{$ref}++;
 $row{$response}{'byhodreq'}{$v}{$hourofday}++;
 $row{$response}{'byipsub'}{$v}{$ip}++;
 $row{$response}{'bycontext'}{$v}{$approot}++;
 $row{$response}{'byrefhost'}{$v}{$hkey}++;
 $row{$response}{'byrefhosthod'}{$v}{$dkey}++;

}
else {
 print "skiping $_\n";
}

Wednesday, March 14, 2012

Please Log Everything with a Log4j.xml to my screen....

It's sad to put this down however every time I need it, I forget the syntax... whats the proper syntax to answer my "please log everything to the screen" question...
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration PUBLIC "-//LOGGER" "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
<log4j:configuration>
    <!-- 
         an appender is an output destination, such as the console or a file;
         names of appenders are arbitrarily chosen
    -->
    <appender name="stdout" class="org.apache.log4j.ConsoleAppender">
        <layout class="org.apache.log4j.PatternLayout">
   <param name="ConversionPattern"  value="%d %-5p %c (%F:%L) %m%n"/>  

        </layout>
    </appender>
     <appender name="stderr" class="org.apache.log4j.ConsoleAppender">
        <param name="target" value="System.err"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%-5p %d [%t][%F:%L] : %m%n" />
        </layout>
    </appender>
 
    <!-- the root category -->
        <!-- 
            all log messages of level "debug" or higher will be logged, unless defined otherwise 
            all log messages will be logged to the appender "stdout", unless defined otherwise 
        -->
<root>
        <priority value="ALL"/>
        <appender-ref ref="stdout" />
        <appender-ref ref="stderr" />
    </root>
</log4j:configuration>