[ic] Cheesy helper script -- lastsyn
Mike Heins
mikeh at perusion.com
Sun Mar 30 15:08:59 UTC 2014
I have looked in the IC error log thousands of times in my life,
and can't believe I didn't write this script before.
Attached.
LASTSYN(1) User Contributed Perl Documentation LASTSYN(1)
NAME
lastsyn -- display last syntax error from error log
SYNOPSIS
lastsyn [-n numlines] [file]
DESCRIPTION
Displays the last syntax error from an Interchange error log. Designed
to avoid having to edit the file to find such things.
If no file name is given to display, assumes you are in the catalog
directory and defaults to <logs/error.log>. If you have the older style
catalog where the errors are in the main directory, you would do:
lastsyn error.log
If you wanted to display it from an arbitrary file:
lastsyn /path/to/the/file/error.log
OPTIONS
-n NNNN
An option to determine how many lines back the program will look
for the error. Default is 2000. It will still display the most
recent error.
AUTHOR
Mike Heins, <heins at icdevgroup.org.
BUGS
The usual number.
perl v5.14.2 2014-03-30 LASTSYN(1)
--
Mike Heins
Perusion -- Expert Interchange Consulting http://www.perusion.com/
phone +1.765.253.4194 <mikeh at perusion.com>
Some people have twenty years of experience, some people have
one year of experience twenty times over. -- Anonymous
-------------- next part --------------
#!/usr/bin/perl
use Getopt::Std;
my %opt;
getopts('n:', \%opt);
=head1 NAME
lastsyn -- display last syntax error from error log
=head1 SYNOPSIS
lastsyn [-n numlines] [file]
=head1 DESCRIPTION
Displays the last syntax error from an Interchange error log. Designed to avoid
having to edit the file to find such things.
If no file name is given to display, assumes you are in the catalog
directory and defaults to <logs/error.log>. If you have the older style
catalog where the errors are in the main directory, you would do:
lastsyn error.log
If you wanted to display it from an arbitrary file:
lastsyn /path/to/the/file/error.log
=head2 OPTIONS
=over 4
=item -n NNNN
An option to determine how many lines back the program will look for the error.
Default is 2000. It will still display the most recent error.
=back
=head1 AUTHOR
Mike Heins, <heins at icdevgroup.org.
=head1 BUGS
The usual number.
=cut
my $fn = shift || 'logs/error.log';
my $num = $opt{n} || 2000;
my @lines = `tail -n$num $fn`;
my @syn;
my $in;
for(@lines) {
if(/^[^>].*Safe.*syntax error/) {
@syn = ($_);
$in = 1;
}
elsif($in and /^>/) {
push @syn, $_;
}
else {
undef $in;
}
}
my $tmpdir = "/tmp/syntax";
-d $tmpdir or mkdir $tmpdir || die "no mkdir: $tmpdir";
my $now = time();
my $tmpfile = "$tmpdir/$$.$now.syntax";
open OUT, "> $tmpfile"
or die "creat $tmpfile: $!\n";
print OUT join "", @syn;
close OUT;
my $morecmd = $ENV{PAGER} || 'less';
exit unless -s $tmpfile;
system "$morecmd $tmpfile";
More information about the interchange-users
mailing list