How To Calculate Dates In Perl Using Date::Manip

Author: , September 18th, 2017

1 2 3 4 my $created_at  = ’2017-09-18T13:43:40Z’; my $marker      = DateCalc(’today’,’30 days ago’); my $cmp = Date_Cmp($created_at,$marker); if ($cmp < 0) { print "Older than marker!\n"; } else { print "Same date or later than marker\n"; } my $created_at = ’2017-09-18T13:43:40Z’; my $marker = DateCalc(‘today’,’30 days ago’); my $cmp = Date_Cmp($created_at,$marker); if […]

How To Watch https Calls to Apache 2.4 using Perl and mod_status

Author: , September 5th, 2017

Step 1: Enable Apache status and lock it down: Make sure mod_status is being loaded: grep -Rn mod_status /etc/httpd/* 1 /etc/httpd/conf.modules.d/00-base.conf:58:LoadModule status_module modules/mod_status.so /etc/httpd/conf.modules.d/00-base.conf:58:LoadModule status_module modules/mod_status.so Add support for the call just under the first DocumentRoot statement: vim /etc/httpd/conf/httpd.conf 1 2 3 4 5 6 <Location /server-status>     SetHandler server-status     Require ip […]

How To Batch Search and Replace Multiple Files Using PERL

Author: , October 16th, 2014

Using PERL, we can easily do a search and replace across multiple files. perl -pi -w -e ‘s/SEARCH_FOR/REPLACE_WITH/g;’ FILE_LIST The following example will replace all occurrences of “hello” with “goodbye” inside files ending with .txt: 1 perl -pi -w -e ‘s/hello/goodbye/g;’ *.txt perl -pi -w -e ‘s/hello/goodbye/g;’ *.txt To handle special characters, use the hex […]

How To Force Getopt::Long To Be Case Sensitive in Perl

Author: , March 19th, 2014

1 use Getopt::Long qw(:config no_ignore_case); use Getopt::Long qw(:config no_ignore_case);

How To Fix CPAN Error Undefined subroutine &IO::Uncompress::Base::readonly

Author: , December 26th, 2013

CPAN Error: Undefined subroutine &IO::Uncompress::Base::readonly called at /usr/lib/perl5/site_perl/5.8.8/IO/Uncompress/Base.pm Looks like CentOS update installs an older version of the Scalar::Util so that Perl could not load the module. Download the Scalar::Util module and manually install it: 1 2 3 4 5 6 7 wget http://search.cpan.org/CPAN/authors/id/P/PE/PEVANS/Scalar-List-Utils-1.35.tar.gz tar xvzf Scalar-List-Utils-*.tar.gz cd Scalar-List-Utils-* perl Makefile.PL gmake gmake test gmake […]

How to Patch CGI::Application::Plugin::ConfigAuto to Run Perl in Taint Mode

Author: , April 13th, 2012

I had to patch the distribution by adding the following variable into the code: $Config::Auto::Untaint = 1; Here is the fix on AWS Linux: vim /usr/local/share/perl5/CGI/Application/Plugin/ConfigAuto.pm 141 sub cfg { 142 my $self = shift; 143 144 if (!$self->{__CFG}) { 145 require Config::Auto; 146 $Config::Auto::Untaint = 1; (ADD THIS NEW LINE HERE)

How To Determine Your Perl Module Version

Author: , April 12th, 2012

For example, to see the version for DBD::mysql, do this: perl -MDBD::mysql -we ‘print $DBD::mysql::VERSION;’

How To Cleanup Hacked WordPress PHP Code Using A Perl Script

Author: , March 21st, 2012

Perl to the Rescue! This perl script cleans just one type of infection as an example. Vary the script to search for and clean other combinations and patterns. Also, the script is deliberately written long-hand and verbose, and could be significantly more compact and efficient. It was done this way for ease of use and […]

How To Install ec2-consistent-snapshot On AWS/CentOS

Author: , December 30th, 2011

1 2 3 yum –enablerepo=epel install perl-Net-Amazon-EC2 perl-File-Slurp perl-DBI perl-DBD-MySQL perl-Net-SSLeay perl-IO-Socket-SSL perl-Time-HiRes perl-Params-Validate ca-certificates wget -O /opt/aws/bin/ec2-consistent-snapshot http://bazaar.launchpad.net/~alestic/ec2-consistent-snapshot/trunk/download/head:/ec2consistentsnapsho-20090928015038-9m9x0fc4yoy54g4j-1/ec2-consistent-snapshot chmod 0775 /opt/aws/bin/ec2-consistent-snapshot yum –enablerepo=epel install perl-Net-Amazon-EC2 perl-File-Slurp perl-DBI perl-DBD-MySQL perl-Net-SSLeay perl-IO-Socket-SSL perl-Time-HiRes perl-Params-Validate ca-certificates wget -O /opt/aws/bin/ec2-consistent-snapshot http://bazaar.launchpad.net/~alestic/ec2-consistent-snapshot/trunk/download/head:/ec2consistentsnapsho-20090928015038-9m9x0fc4yoy54g4j-1/ec2-consistent-snapshot chmod 0775 /opt/aws/bin/ec2-consistent-snapshot http://alestic.com/2009/09/ec2-consistent-snapshot http://www.thatsgeeky.com/2011/05/ec2-consistent-snapshot-on-amazons-linux-ami/ http://www.thatsgeeky.com/2011/06/rotating-ebs-snapshots-ec2-prune-snapshots/

How To Create a Web Request Sniffer Using tcpdump and Perl

Author: , November 3rd, 2011

YMMV… 1 2 3 4 5 6 7 8 9 10 #!/usr/bin/perl use strict; $|  = 1; our $LIMIT = shift || 5000; open (STDIN,"/usr/sbin/tcpdump -Atpn dst port 80 |"); while (<>) {     last unless $LIMIT–;     next unless /get|host|post|http|xml/i;     print; } #!/usr/bin/perl use strict; $| = 1; our $LIMIT […]