Yum: Checking for updates.

Friday, September 23rd, 2005

Here’s a quick script you can put in your cron rotation to check and see if there are any updates available and what they are:


#!/bin/bash

yum_output=/tmp/yum-check-update-output.txt
python=/usr/bin/python1.5
yum=/usr/bin/yum

$python $yum check-update > $yum_output

yum_return_code="$?"

case $yum_return_code in
100)
# Packages available for update.
echo '********************************************************'
echo "The following packages need to be udpated on $HOSTNAME"
echo '********************************************************'
echo ''
cat $yum_output
;;
0)
# No packages available for update.
;;
*)
echo "YUM: Undefined return code: $yum_return_code ."
exit 1
esac

exit 0

Count bandwidth

Saturday, September 3rd, 2005

Ed: this has been sitting in my “drafts” box for a while now, so I figure I might as well just push it out.

Here’s a script I wrote to count the bandwidth used from the Apache access_log:

#!/usr/bin/perl -w

use strict;

my $access_log = $ARGV[0];
my $total = 0;
my @chunks;

open(LOGFILE, $access_log) or die "Could not open $access_log $!";

# count amount of data.
while(<logfile>)
{
@chunks = split();
if($chunks[9] =~ /\d/)
{ $total += $chunks[9]; }
}

close(LOGFILE);

# convert to human readable; 1024 * 1024 = 1048576.
$total /= 1048576;

print "Amount of bandwidth : $total MB\n";

Vulnerable phpBB : Find and Disable.

Monday, July 18th, 2005

Here’s a little script I wrote that attempts to find and disable old phpBB instances that may be vulnerable to the recent phpBB Worm in the wild.


#!/usr/bin/perl
# Name: Augie Schwer
# File: find-vuln.pl
# Date: 18, July 2005
# Purpose: Find vulnerable phpBBs and disable them.

use strict;

my ($line,$location,$user,$this_version,$newest_version);

$newest_version = '2005/06/26';

# where to search.
my $webdir = '/home/WWW_pages/';

# spawn sub shell and find the viewtopic.php and capture its version and location.
my @output = `find $webdir -type f -name viewtopic.php -print | xargs --verbose grep '\$Id: viewtopic.php,v' 2>&1`;

# parse out location and version.
foreach $line (@output)
{
if($line =~ /(.+?): .+ \$Id: viewtopic.php,v .+ (\d{4}\/\d{2}\/\d{2}) .+/)
{
$location = $1;
$this_version = $2;

# old phpBB, disable it.
if($this_version ne $newest_version)
{ print "OLD PHPBB\n" ; `chmod 000 $location`; }

print "Location: $location \n";
print "This V : $this_version \n";
print "New V : $newest_version \n";
}
}