Script to obtain the count of archive logs applied during recovery

Pass the start date + time and end date + time to the following script. It looks at the alert log file and obtains the no of archive logs that have been applied during media recovery in that time interval.
#!/usr/bin/perl -w

BEGIN { push @INC,”/home/user/TimeDate-1.16/lib/” }
use Date::Parse;
$start=str2time(@ARGV[0]);
chomp(@ARGV[1]);
$end=str2time(@ARGV[1]);

$log=’path to the log file’;
open(ALERTLOGFILE,$log) or die “Not able to [...]

Commenting and Uncommeting read-only in my.cnf across multiple servers

For commenting the following snippets can be used :
sudo perl -i -p -e ‘ print “#” . ” ” if !/^#/ && /^read-only/; ‘ /etc/my.cnf
sed -i -e ’s/^read-only/#&/g’ cnf
For uncommenting you can use the following snippets :
sudo perl -i -p -e ’s/^#// if /^#/ && /read-only/; ‘ /etc/my.cnf

sed -i -e ’s/^#*read-only/read-only/g’ cnf

Monitor Feed Generation

If there are hourly feeds that are being generated based on time, the we can use the following snippet to go back in time for 2 hours and generate the filename based on requirement.
$timenow=time()-(2*60*60); // Gives the time 2 hours before.
$consfeed= strftime “data_%Y_%m_%d_%H_00_00.xml”, localtime($timenow); // Constructs the filename to be looked for 2 [...]

Transforming Unix Timestamps in logs to date

Logfiles in older unix systems and monitoring systems just log the unix timestamp as the first field in the enteries. When we try to pull out data for a particular date, then it becomes tricky. The following code snippet will help pulling out data for a particular date quite easily
cat <logfile> | perl -lane ‘$_=$F[0]; [...]

Perl Snippet to extract first column

Requirement : Obtain line no and first field (if it is a number) from the following datafile
31726108012^Abicyclepatrolpuyallup^A0^B
31726228012^Acommercialguardseattlesecurity^A0^B
31726230512^Aconstructionguardkentsecurity^A0^B
31726241512^Aeventfederalguardsecurityway^A0^B
^A indicates ctrl + A
perl -n -e ‘@line= split /^A/,$_ ; if (int($line[0]) != 0) { print “$. ” . $line[0] .”\n” }’ datafile
$. gives us the line no.
int(any non numeric value) will return 0.
To generate [...]