Have you seen this package?
sub match_new_rpms() {
# Iterate through a listing of updated RPM
# packages, comparing them one-by-one against
# packages currently installed.
my $workdir = $config{workdir};
my $today = $config{today};
my $ver = $config{version};
my @new = `cat ${workdir}/fresh${ver}-${today}`;
foreach my $fullpkg (@new) {
chomp($fullpkg);
my %fresh_n_clean = ($fullpkg => &chop_extension($fullpkg));
foreach my $rpm (keys %fresh_n_clean) {
my $args = `rpm -qa | grep $fresh_n_clean{$rpm}`;
&download_packages(${fullpkg}) if ($args =~ m/^$/);
}
}
}
sub chop_extension() {
my $fn = shift;
$fn =~ (s/\.i\d{3}\.rpm//g);
$fn =~ (s/\.noarch\.rpm//g);
$fn =~ (s/\.athlon\.rpm//g);
return $fn;
- - - - - - - - - - - - - - - -
Silly split Test.
#! /usr/bin/perl -w
use strict;
my $string="superdog";
my @array = split//,$string;
my $count = @array;
print "\$string = $string\n";
print "There are $count characters in $string.\n";
print "Lets push split those $count characters into an array...\n";
for (my $i=0; $i < $count; $i++) {
print "\t\@array[$i] = $array[$i]\n";
}
- - - - - - - - - - - - - - - -
MySQL Backup
#! /usr/bin/perl
# mysql-backup.pl
# Dump and gzip each MySQL database.
use warnings;
use strict;
my $dbhost = "localhost";
my $dbuser = "root";
my $dbpass = "easy1";
my $date = "`date +%Y-%m-%d`";
my $path = "/path/to/dbbpdir";
my $ext = "gz";
&clean_up($path,$ext);
my($dbh,$sth,$query);
$dbh = (&connect($dbhost,$dbuser,$dbpass));
$query = qq^SHOW DATABASES^;
$sth = $dbh->prepare($query);
$sth->execute();
while(my $ref = $sth->fetchrow_array()) {
my @bp = `mysqldump --user=$dbuser --password=$dbpass --add-drop-t
+able $ref | gzip > $path/$ref.$date.$ext`;
}
$sth->finish();
$dbh->disconnect();
# - - - - - - - - - - - - - - - - -
sub connect() {
use DBI;
my $hostname = shift;
my $dbuser = shift;
my $dbpass = shift;
my $dsn = "DBI:mysql:host=$hostname";
DBI->connect($dsn,$dbuser,$dbpass,{PrintError => 0, RaiseError => 1
+});
}
sub clean_up() {
$path = shift;
$ext = shift;
opendir(BP_DIR,"$path") or die "Cannot open $path: $!\n";
my @old_backups = grep { /\.$ext$/ } readdir BP_DIR;
closedir(BP_DIR);
foreach (@old_backups) {
my @args = ("rm","-f","$path/$_");
system(@args);
}
}
- - - - - - - - - - - - - - - - -
#! /usr/bin/perl -w
use strict;
my $host="wonderwaylabs.com";
my %rec = getips($host);
print "$_ --> $rec{$_}\n" for keys %rec;
sub getips {
my $host = shift;
chomp (my $record = `/usr/bin/host $host`);
my ($notfound,$matches,%records);
$notfound = '\s{1}not\s{1}found\:';
$matches = '^(\S+).*(\d+\.\d+\.\d+\.\d+)$';
if ($record =~ /$notfound/o) {
print "No record for $host\n";
#email_resolution_error($host);
} else {
%records = ( $1 => $2 ) if $record =~ /$matches/o;
}
return %records;
}
- - - - - - - - - - - - - - - - -
(OLD) Service Health Scanner: See NEW
#! /usr/bin/perl
# multimonitor.pl
# monitor http,https,smtp on remote servers.
use strict;
my (@rwebhost,@rswebhost,@rmailhost,$key,%host);
# http
%host = ();
push @rwebhost,"coolsite.com","notcoolsite.com","sheepydeepy.com";
foreach (@rwebhost) {
%host = ($_ => &getips($_));
foreach $key (keys %host) {
&scan_httpd($host{$key},$key);
}
}
# https
push @rswebhost,"secure.coolsite.com";
foreach (@rswebhost) {
%host = ($_ => &getips($_));
foreach $key (keys %host) {
&scan_httpsd($host{$key},$key);
}
}
# smtp
push @rmailhost,"mail.sheepydeepy.com";
foreach (@rmailhost) {
%host = ($_ => &getips($_));
foreach $key (keys %host) {
&scan_smtp($host{$key},$key);
}
}
sub getips() {
my $host = shift;
my ($name,$aliases,$addrtype,$length,@addrs,@ips);
(($name, $aliases, $addrtype, $length, @addrs) = gethostbyname($host
+))
|| &email_resolution_error($host);
foreach (@addrs) {
@ips = join('.',unpack('C4',$_)),"\n";
return @ips;
}
}
# ===================================
sub scan_httpd() {
# Scan for HTTP service.
my @ips = shift;
my @hostname = shift;
my $port = "80";
for (my $i = 0; $i < @ips; $i++) {
my @results = `/usr/bin/nmap -P0 -p$port -oG - $ips[$i] | grep \"S
+tatus: Up\"`;
for (@results) {
&email_connection_error($hostname[$i]) if $_ =~ $ips[$i];
}
}
}
sub scan_httpsd() {
# Scan for HTTPS service.
my @ips = shift;
my @hostname = shift;
my $port = "443";
for (my $i = 0; $i < @ips; $i++) {
my @results = `/usr/bin/nmap -P0 -p$port -oG - $ips[$i] | grep \"S
+tatus: Up\"`;
for (@results) {
&email_connection_error($hostname[$i]) if $_ =~ $ips[$i];
}
}
}
sub scan_smtp() {
# Scan for SMTP service.
my @ips = shift;
my @hostname = shift;
my $port = "25";
for (my $i = 0; $i < @ips; $i++) {
my @results = `/usr/bin/nmap -P0 -p$port -oG - $ips[$i] | grep \"S
+tatus: Up\"`;
for (@results) {
&email_connection_error($hostname[$i]) if $_ =~ $ips[$i];
}
}
}
sub email_resolution_error() {
my $rnode = shift;
my $hostname = `/bin/uname -n`;
chomp($hostname);
open(SENDMAIL, "|/usr/lib/sendmail -oi -t")
or die "Cannot fork for sendmail: $!\n";
print SENDMAIL <<EOF;
From: Multi-Monitor <nobody\@monitor.domain.com>
To: System Admin <someone\@anotherdomain.com>,somemobile\@otherdomain.
+net
Subject: The domain $rnode cannot be resolved!
This email is generated by the Multi-Monitor script on $hostname...
WARNING: The domain $rnode cannot be resolved!
EOF
close(SENDMAIL) or warn "Oops, sendmail did not close nicely";
}
sub email_connection_error() {
my $hostname = `/bin/uname -n`;
my $remote_server = shift;
chomp($hostname);
chomp($remote_server);
# switch $remote_server back to a hostname.
open(SENDMAIL, "|/usr/lib/sendmail -oi -t")
or die "Cannot fork for sendmail: $!\n";
print SENDMAIL <<EOF;
From: Multi-Monitor <nobody\@monitor.domain.com>
To: System Admin <someone\@anotherdomain.com>,somemobile\@otherdomain.
+net
Subject: Connection Trouble on $remote_server!
This email is generated by the Mulit-Monitor script on $hostname...
WARNING: $remote_server cannot be contacted!
EOF
close(SENDMAIL) or warn "Oops, sendmail did not close nicely";
}
- - - - - - - - - - - - - - - - -
|