Skip to content

Instantly share code, notes, and snippets.

View eqhmcow's full-sized avatar

Daniel S. Sterling eqhmcow

View GitHub Profile
@eqhmcow
eqhmcow / find_timeouts.sh
Created November 27, 2012 15:22
parse combined access logs for IPs that are making requests that timeout
ls /usr/local/arcos/logs/proxy_access_log.* -t1 | head -1 | (read i; cat $i | egrep '" 40[08] ') | grep -v ' 10\.0\.30\.2 ' | perl -p -e '($vhost, $ip, $date, $method, $url, $protocol, $alt_url, $code, $bytes, $referrer, $ua) = (m/^(\S+)\s(\S+)\s\S+\s+(?:\S+\s+)+\[([^]]+)\]\s"(\S*)\s?(?:((?:[^"]*(?:\\")?)*)\s([^"]*)"\s|((?:[^"]*(?:\\")?)*)"\s)(\S+)\s(\S+)\s"((?:[^"]*(?:\\")?)*)"\s"(.*)"$/x); die "Could not match $_" unless $ip; $alt_url ||= ""; $url ||= $alt_url; $_="$ip $vhost\n"' | sort | uniq -c | sort -n
@eqhmcow
eqhmcow / parse_db.pl
Created August 7, 2012 08:22
line noise
use strict;
use warnings;
my @element;
my @element_ids;
my @element_index;
while (<>) {
if (m/INSERT INTO `element` /) {
parse_element($_);
next;
@eqhmcow
eqhmcow / iscsi-blockdev-uid.pl
Created July 21, 2012 06:14
generate an id based on a block device's iscsi target name and lun number
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
use Digest::SHA1 qw(sha1_base64);
my $hash;
GetOptions("hash" => \$hash);
@eqhmcow
eqhmcow / interfaces
Created May 25, 2012 23:51
ubuntu network interfaces file - needed to rmmod bonding before it would reliably work over reboots
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
auto bond0
iface bond0 inet manual
# bizarre, but this works...
@eqhmcow
eqhmcow / divide.pl
Created January 3, 2012 19:09
safe divide by zero
#!/usr/bin/perl
sub divide {
($a, $b) = @_;
$c = eval { $a / $b };
$@ =~ m/Illegal division by zero/ && rand() > .5 ? ($b = 1) : ($b = -1);
$@ && ($c = $a / $b);
return $c;
}
@eqhmcow
eqhmcow / bash-caps
Last active July 18, 2022 11:11
SYNTAX ERROR: UNEXPECTED END OF FILE
cp /bin/bash ./bash.caps; echo "this will take a while, be patient..."; strings -n 10 bash.caps | egrep -e '^.* .* .* .*$' | grep -Pv '^(_|\s)|\$|\[|;|@|\s\s' | while read i; do perl -pi -e "$/=\"\\0\";next if/ function\S|binding|^(case|select|for|trap|builtin)|_.*_/;next unless m@\\Q$i\\E@;sub b{return\$_ if/%/;uc}\$_=join' ',map{b()}split/ /" bash.caps; done; chmod a+x bash.caps; ./bash.caps
@eqhmcow
eqhmcow / apache-logtop-README
Last active July 29, 2019 14:54
Real-time top-like requests-per-second average for httpd request logs - similar to apachetop
DESCRIPTION
logstat.pl and logtop.pl
These scripts show current and average request-per-second counts based on
apache access logs in real-time.
You can see the total requests-per-second as well as a breakdown by:
* vhost
* URL
@eqhmcow
eqhmcow / hfsc-shape.sh
Last active August 2, 2023 11:59
HFSC - linux traffic shaping's best kept secret
#!/bin/bash
# As the "bufferbloat" folks have recently re-discovered and/or more widely
# publicized, congestion avoidance algorithms (such as those found in TCP) do
# a great job of allowing network endpoints to negotiate transfer rates that
# maximize a link's bandwidth usage without unduly penalizing any particular
# stream. This allows bulk transfer streams to use the maximum available
# bandwidth without affecting the latency of non-bulk (e.g. interactive)
# streams.
@eqhmcow
eqhmcow / logger.pl
Created March 22, 2011 21:10
logger.pl reimplements (most of) logger(1). Thanks to Perl, this logger hasn't got arbitrary message length limits; so you can syslog(3) messages bigger than the default logger(1) buffer (usually 1k) -- as long as your syslogd supports doing that.
#!/usr/bin/perl
use strict;
use warnings;
=pod
=head1 NAME
B<logger.pl> - a shell command interface to the syslog(3) system log module
@eqhmcow
eqhmcow / puppet NFS
Created December 23, 2010 14:12
share NFS mounts on RHEL/CentOS with puppet, using augeas to manage exports file
# modules/nfs/manifests/init.pp
class nfs_server {
file { "destroy_exports":
path => "/etc/exports.puppet",
ensure => present,
source => "puppet://$servername/modules/nfs/empty",
}
package { "portmap":