computer:~ me$ sed -n "57450,\$p" pf/app/logs/server/trace.log
Rants and ravings of a semi-autistic developer who has a hard time remembering idiotic nonsense details. Why remember it, when you know where to find it.
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?
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 2Example 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>
Friday, February 3, 2012
Mac OSX - running xterm and X11 xhost: unable to open display
So alright you have Mac OSX. Yay I
I have a VPN to the office. Yay II (ip vpn adapter: 172.18.146.250)
I have oodles of linux boxes! Yay III
The problem:
One odd ball process on my linux will throw a X11 Graphics error so how to get around that....
Try 1: Do the standard export and xhost + trick
open Terminal.app and run:
computer:~ ~$ export DISPLAY=172.18.146.250:0 computer:~ ~$ xhost + xhost: unable to open display "172.18.146.250:0" computer:~ ~$Thats not right... lets start the Xserver in background (X Server startcmd is 'X').... and do this again...
computer:~ ~$ X &
launch_msg("CheckIn") IPC failure: Operation not permitted
Xquartz: Unable to locate waiting server: org.x.X11
Xquartz: X11.app = /Applications/Utilities/X11.app/Contents/MacOS/X11
Xquartz: Starting X server: /Applications/Utilities/X11.app/Contents/MacOS/X11 --listenonly
..SCM BUILD BOX profile been setup..
================================================
X11.app: main(): argc=2
argv[0] = /Applications/Utilities/X11.app/Contents/MacOS/X11.bin
argv[1] = --listenonly
Waiting for startup parameters via Mach IPC.
X11.app: No launchd socket handed off, unsetting DISPLAY
X11.app: do_start_x11_server(): argc=1
argv[0] = X
Xquartz starting:
X.Org X Server 1.4.2-apple56
Build Date: 20100624
(EE) XKB: Couldn't open rules file /usr/X11/share/X11/xkb/rules/base
(EE) XKB: Couldn't open rules file /usr/X11/share/X11/xkb/rules/base
computer:~ ~$
Try 2:
Now open the xterm under the X11 Application that has been started...
bash-3.2$ export DISPLAY=172.18.146.250:0 bash-3.2$ xhost + access control disabled, clients can connect from any host bash-3.2$
Subscribe to:
Posts (Atom)