├── ANSIColor.pm ├── LogMini.pm ├── POST ├── README.md ├── ack-standalone ├── bandwidth.pl ├── basename.pl ├── batch_send.pl ├── bgend_symbol.pl ├── calc_run_size.pl ├── cat.pl ├── cloc-1.00.pl ├── cloc-1.56.pl ├── cloc.pl ├── color.pl ├── cpanm ├── daemon.pl ├── demo.pl ├── dos2unix.pl ├── dumpvim2html.pl ├── fincore ├── free.pl ├── getopt.pl ├── iputils.pm ├── json.pl ├── kickOut.pl ├── kill.pl ├── log_server_status ├── ls.pl ├── mc-conn-tester.pl ├── memcache-top.pl ├── memcached-tool ├── mpstat.pl ├── namespace.pl ├── netwatch.pl ├── oneline.pl ├── orzdba.pl ├── post.pl ├── replaceMatchLine.pl ├── rm ├── scanner.pl ├── selectserver.pl ├── slowloris.pl ├── socket.pl ├── split-logfile ├── stats.pl ├── synflood.pl ├── tasks.pl ├── template.pl ├── timeparse.pl ├── top.pl ├── type-o-serve.pl ├── update.pl ├── urlgrep.pl ├── utils.pm ├── version.pl └── which /LogMini.pm: -------------------------------------------------------------------------------- 1 | package LogMini; 2 | # 3 | # Author: soarpenguin 4 | # First release Mar.29 2014 5 | ################################################## 6 | # usage of LogMini.pm, add code like: 7 | # use lib "path"; #path is the file of LogMini.pm 8 | # use LogMini; 9 | # 10 | # LogMini log libirary for perl. 11 | ################################################## 12 | use strict; 13 | use warnings; 14 | use Term::ANSIColor qw//; 15 | use Data::Dumper; 16 | $| = 1; 17 | 18 | BEGIN { 19 | use Exporter(); 20 | use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); 21 | $VERSION = 0.0.1; 22 | @ISA = qw(Exporter); 23 | @EXPORT = map { ("log_" . $_) } qw/crit critf warn warnf info infof debug debugf croak croakf/; 24 | push @EXPORT, 'ddf'; 25 | } 26 | 27 | sub __FUNC__ { (caller(0))[3] } 28 | 29 | #[2014.3.29 21:7:37][Trace][[Notice][main::usage()]][test.pl:13]teesssss 30 | our $PRINT = sub { 31 | my ( $time, $type, $message, $trace, $raw_message) = @_; 32 | warn "[$time][$type][$trace]$message\n"; 33 | }; 34 | 35 | our $DIE = sub { 36 | my ( $time, $type, $message, $trace, $raw_message) = @_; 37 | die "[$time][$type][$trace]$message\n"; 38 | }; 39 | 40 | our $DEFAULT_COLOR = { 41 | info => { 42 | text => 'green', 43 | }, 44 | debug => { 45 | text => 'red', 46 | background => 'white', 47 | }, 48 | 'warn' => { 49 | text => 'black', 50 | background => 'yellow', 51 | }, 52 | 'critical' => { 53 | text => 'black', 54 | background => 'red' 55 | }, 56 | 'error' => { 57 | text => 'red', 58 | background => 'black' 59 | } 60 | }; 61 | 62 | if ($ENV{LM_DEFAULT_COLOR}) { 63 | # LEVEL=FG;BG:LEVEL=FG;BG:... 64 | for my $level_color (split /:/, $ENV{LM_DEFAULT_COLOR}) { 65 | my($level, $color) = split /=/, $level_color, 2; 66 | my($fg, $bg) = split /;/, $color, 2; 67 | $LogMini::DEFAULT_COLOR->{$level} = { 68 | $fg ? (text => $fg) : (), 69 | $bg ? (background => $bg) : (), 70 | }; 71 | } 72 | } 73 | 74 | our $ENV_DEBUG = "LM_DEBUG"; 75 | our $AUTODUMP = 0; 76 | our $LOG_LEVEL = 'DEBUG'; 77 | our $TRACE_LEVEL = 0; 78 | #our $COLOR = $ENV{LM_COLOR} || 0; 79 | our $COLOR = 1; 80 | our $ESCAPE_WHITESPACE = 1; 81 | 82 | my %log_level_map = ( 83 | DEBUG => 1, 84 | INFO => 2, 85 | WARN => 3, 86 | CRITICAL => 4, 87 | MUTE => 0, 88 | ERROR => 99, 89 | ); 90 | 91 | sub import { 92 | my $class = shift; 93 | my $package = caller(0); 94 | my @args = @_; 95 | 96 | my %want_export; 97 | my $env_debug; 98 | while ( my $arg = shift @args ) { 99 | if ( $arg eq 'env_debug' ) { 100 | $env_debug = shift @args; 101 | } else { 102 | $want_export{$arg} = 1; 103 | } 104 | } 105 | 106 | if ( ! keys %want_export ) { 107 | #all 108 | $want_export{$_} = 1 for @EXPORT; 109 | } 110 | 111 | no strict 'refs'; 112 | for my $f (grep !/^debug/, @EXPORT) { 113 | if ( $want_export{$f} ) { 114 | *{"$package\::$f"} = \&$f; 115 | } 116 | } 117 | 118 | for my $f (map { ($_ . 'f', $_ . 'ff') } qw/debug/) { 119 | if ( $want_export{$f} ) { 120 | if ( $env_debug ) { 121 | *{"$package\::$f"} = sub { 122 | local $TRACE_LEVEL = $TRACE_LEVEL + 1; 123 | local $ENV_DEBUG = $env_debug; 124 | $f->(@_); 125 | }; 126 | } else { 127 | *{"$package\::$f"} = \&$f; 128 | } 129 | } 130 | } 131 | 132 | } 133 | 134 | sub log_crit { 135 | print_log( "CRITICAL", 0, @_ ); 136 | } 137 | 138 | sub log_warn { 139 | print_log( "WARN", 0, @_ ); 140 | } 141 | 142 | sub log_info { 143 | print_log( "INFO", 0, @_ ); 144 | } 145 | 146 | sub log_debug { 147 | return if !$ENV{$ENV_DEBUG} || $log_level_map{DEBUG} < $log_level_map{uc $LOG_LEVEL}; 148 | print_log( "DEBUG", 0, @_ ); 149 | } 150 | 151 | sub log_critf { 152 | print_log( "CRITICAL", 1, @_ ); 153 | } 154 | 155 | sub log_warnf { 156 | print_log( "WARN", 1, @_ ); 157 | } 158 | 159 | sub log_infof { 160 | print_log( "INFO", 1, @_ ); 161 | } 162 | 163 | sub log_debugf { 164 | return if !$ENV{$ENV_DEBUG} || $log_level_map{DEBUG} < $log_level_map{uc $LOG_LEVEL}; 165 | 166 | print_log( "DEBUG", 1, @_ ); 167 | } 168 | 169 | sub log_croak { 170 | local $PRINT = $DIE; 171 | local $LOG_LEVEL = 'DEBUG'; 172 | 173 | print_log( "ERROR", 0, @_ ); 174 | } 175 | 176 | sub log_croakf { 177 | local $PRINT = $DIE; 178 | local $LOG_LEVEL = 'DEBUG'; 179 | 180 | print_log( "ERROR", 1, @_ ); 181 | } 182 | 183 | sub print_log { 184 | my $tag = shift; 185 | my $full = shift; 186 | 187 | my $_log_level = $log_level_map{uc $LOG_LEVEL} || return; 188 | return unless $log_level_map{$tag} >= $_log_level; 189 | 190 | my $time = &get_now_time(); 191 | 192 | my $trace; 193 | if ( $full ) { 194 | my $i = $TRACE_LEVEL + 1; 195 | my @stack; 196 | while ( my @caller = caller($i) ) { 197 | #($package, $filename, $line $subroutine) = caller; 198 | push @stack, $caller[1] . ":" . $caller[2]; 199 | $i++; 200 | } 201 | $trace = join " ,", @stack; 202 | } else { 203 | my @caller = caller($TRACE_LEVEL + 1); 204 | #($package, $filename, $line, $subroutine) = caller; 205 | $trace = $caller[1] . ":" . $caller[2]; 206 | } 207 | 208 | my $messages = ''; 209 | if ( @_ == 1 && defined $_[0]) { 210 | $messages = $AUTODUMP ? '' . LogMini::Dumper->new($_[0]) : $_[0]; 211 | } elsif ( @_ >= 2 ) { 212 | $messages = sprintf(shift, map { $AUTODUMP ? LogMini::Dumper->new($_) : $_ } @_); 213 | } 214 | 215 | if ($ESCAPE_WHITESPACE) { 216 | $messages =~ s/\x0d/\\r/g; 217 | $messages =~ s/\x0a/\\n/g; 218 | $messages =~ s/\x09/\\t/g; 219 | } 220 | 221 | my $raw_message = $messages; 222 | if ( $COLOR ) { 223 | $messages = Term::ANSIColor::color($DEFAULT_COLOR->{lc($tag)}->{text}) 224 | . $messages . Term::ANSIColor::color("reset") 225 | if $DEFAULT_COLOR->{lc($tag)}->{text}; 226 | $messages = Term::ANSIColor::color("on_" . $DEFAULT_COLOR->{lc($tag)}->{background}) 227 | . $messages . Term::ANSIColor::color("reset") 228 | if $DEFAULT_COLOR->{lc($tag)}->{background}; 229 | } 230 | 231 | $PRINT->( 232 | $time, 233 | $tag, 234 | $messages, 235 | $trace, 236 | $raw_message 237 | ); 238 | } 239 | 240 | sub ddf { 241 | my $value = shift; 242 | LogMini::Dumper::dumper($value); 243 | } 244 | 245 | sub get_now_time { 246 | my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time); 247 | my $now_time = sprintf("%d.%d.%d %02d:%02d:%02d", 248 | $year + 1900, $mon + 1, $mday, $hour, $min, $sec); 249 | 250 | return "$now_time"; 251 | } 252 | 1; 253 | 254 | ##################################################################### 255 | package LogMini::Dumper; 256 | 257 | use strict; 258 | use warnings; 259 | use base qw/Exporter/; 260 | use Data::Dumper; 261 | use Scalar::Util qw/blessed/; 262 | 263 | use overload 264 | '""' => \&stringfy, 265 | '0+' => \&numeric, 266 | fallback => 1; 267 | 268 | sub new { 269 | my ($class, $value) = @_; 270 | bless \$value, $class; 271 | } 272 | 273 | sub stringfy { 274 | my $self = shift; 275 | my $value = $$self; 276 | 277 | if ( blessed($value) && (my $stringify = overload::Method( $value, '""' ) 278 | || overload::Method( $value, '0+' )) ) { 279 | $value = $stringify->($value); 280 | } 281 | dumper($value); 282 | } 283 | 284 | sub numeric { 285 | my $self = shift; 286 | my $value = $$self; 287 | 288 | if ( blessed($value) && (my $numeric = overload::Method( $value, '0+' ) 289 | || overload::Method( $value, '""' )) ) { 290 | $value = $numeric->($value); 291 | } 292 | $value; 293 | } 294 | 295 | sub dumper { 296 | my $value = shift; 297 | 298 | if ( defined $value && ref($value) ) { 299 | local $Data::Dumper::Terse = 1; 300 | local $Data::Dumper::Indent = 0; 301 | local $Data::Dumper::Sortkeys = 1; 302 | $value = Data::Dumper::Dumper($value); 303 | } 304 | $value; 305 | } 306 | 307 | 1; 308 | __END__ 309 | 310 | -------------------------------------------------------------------------------- /POST: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | 3 | eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}' 4 | if 0; # not running under some shell 5 | 6 | # $Id: lwp-request,v 2.7 2005/12/06 12:16:28 gisle Exp $ 7 | # 8 | # Simple user agent using LWP library. 9 | 10 | =head1 NAME 11 | 12 | lwp-request - Simple command line user agent 13 | 14 | =head1 SYNOPSIS 15 | 16 | lwp-request [-aeEdvhx] [-m method] [-b ] [-t ] 17 | [-i ] [-c ] [-C ] 18 | [-p ] [-o ] ... 19 | 20 | =head1 DESCRIPTION 21 | 22 | This program can be used to send requests to WWW servers and your 23 | local file system. The request content for POST and PUT 24 | methods is read from stdin. The content of the response is printed on 25 | stdout. Error messages are printed on stderr. The program returns a 26 | status value indicating the number of URLs that failed. 27 | 28 | The options are: 29 | 30 | =over 4 31 | 32 | =item -m 33 | 34 | Set which method to use for the request. If this option is not used, 35 | then the method is derived from the name of the program. 36 | 37 | =item -f 38 | 39 | Force request through, even if the program believes that the method is 40 | illegal. The server might reject the request eventually. 41 | 42 | =item -b 43 | 44 | This URI will be used as the base URI for resolving all relative URIs 45 | given as argument. 46 | 47 | =item -t 48 | 49 | Set the timeout value for the requests. The timeout is the amount of 50 | time that the program will wait for a response from the remote server 51 | before it fails. The default unit for the timeout value is seconds. 52 | You might append "m" or "h" to the timeout value to make it minutes or 53 | hours, respectively. The default timeout is '3m', i.e. 3 minutes. 54 | 55 | =item -i