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

Init script for rsyncd.

Saturday, September 3rd, 2005

Ed: another one that was sitting in “drafts” for months.

#!/bin/bash
#
# Startup script for rsyncd.
#
# chkconfig: 345 86 16
# description: rsync rocks.
#

case “$1″ in
start)
echo “Starting rsyncd…”
/opt/rsync/bin/rsync –daemon –ipv4
;;
stop)
echo “Stopping rsyncd…”
killall /opt/rsync/bin/rsync
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
echo “Usage: $0 {start|stop|restart}”
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";
}
}

Supybot init script for Debian.

Sunday, April 17th, 2005

Supybot is a neat little IRC bot written in Python. I had been looking for a bot to do some logging of my favorite IRC channel (#nblug on irc.nblug.org). The setup was pretty easy and the documentation is nice, but the one thing I didn’t find was an init script, so I modified one from an existing blootbot init script.


#! /bin/sh
#
# supybot init script
#
#
# Cobbled together from the blootbot init script.
#

PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/supybot
NAME=supybot
DESC=supybot

test -f $DAEMON || exit 0

set -e

case "$1" in
start)
echo -n "Starting $DESC: "
start-stop-daemon --start --quiet --pidfile /var/run/supybot/$NAME.pid \
--chuid supybot --exec $DAEMON -- --daemon /etc/supybot/nibler.conf
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon --stop --quiet --pidfile /var/run/supybot/$NAME.pid \
--oknodo --exec /usr/bin/python
echo "$NAME."
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart}" >&2
exit 1
;;
esac

exit 0

Note: I am still a big Mandriva weenie, but the server this bot runs on is a Debian box.

Regular Expression Library

Wednesday, March 9th, 2005

Regular Expression Library

Oh sweet nectar; a repository for your favorite regular expressions.

Get an interface’s information

Monday, March 15th, 2004

Here is a bit of code to get an interface’s information; including the interface name, and MAC address:

(more…)

alarmClock

Saturday, February 14th, 2004

I added an HFile for C to the CodeBeautifier plugin, and I want to see how it turns out. Click ‘continue reading’ to see the actual code.

alarmClock is a program I wrote last semester for my Systems Programming course. The program is actually two programs; one that is a menu, and the other that is a timer. Signals are sent between the two processes to coordinate the alarm going off, hitting snooze, and quitting the program all together. Here is a sample with the timer set to five seconds, the snooze set at three seconds, and the ring “tone” set to ‘ringing’.

[augie@gohan alarmClock]$ ./alarmClock -t 5 -s 3 ringing wait_for_child
start
ringing
ringing
snooze
ringing
ringing
quiting
wait_for_child
wait_for_child
wait_for_child
wait_for_child
wait_for_child
child exited with code: 8

(more…)

Fun with powers of two

Friday, February 13th, 2004

Here is one of the problems we had for Theory of Comp. and my solution. It’s an interesting problem, but really just a an excuse to try out the CodeBeautifier plugin for MT.

4)Write a computer program that finds the smallest power of 2 that starts with a given number k. Run the program for k = 97. (For example, the smallest power of 2 that starts with 54 is 239 = 549755813888.)

#!/usr/bin/perl -w

use strict;
use bignum;

my $prefix = $ARGV[0];
my $test_num;
my $n = 0;
my $bool = 1;

while($bool)
{
$test_num = 2 ** $n;
if( $test_num =~ /^($prefix).*/ )
{ $bool = 0; }
else
{ $n = $n + 1; }
}

print "n is $n\n";