" />

mikerochford.com Being technical


Setting a timeout for urllib2 in python2.4

Wait, Did I really say python2.4? Yes, Yes, I did.

Since the timeout argument doesn't exist in python2.4 urllib2.urlopen you will need to override the socket variable manually.


#!/usr/bin/env python

import socket
import urllib2

url = 'http://www.google.com'

    request = urllib2.urlopen(url)
    data = request.read()

Filed under: Programming, python 1 Comment

Cleaning up /boot of old kernels on Debian based Operating systems

dpkg -l | grep linux-image | awk '{print $2}' | egrep -v "($(uname -r)|^linux-image-server$)" | xargs dpkg --purge

Filed under: Uncategorized No Comments

Filesystem backups

I always deal with friend and family's computers. They are always full of viruses and mail-ware. All they care is "Backup my music and pictures." Well I got tired of always trying to search and finding these files on there disk. So I wrote a quick little python script to gather all the files I want based on the file extension. Please see the script below and let me know what you think.


Filed under: Uncategorized No Comments

Find all the perl modules in your script and make sure they are installed

Ever migrated code from one server to another and never remember if you captured all the modules that need to be installed? I have, its a pain in the ass sometimes. So I thought I would throw together a little script to check if I have all the modules I used installed. I have written it in python and perl (Dont ask!)



mrochford@mrochford-linux:~/bin$ ./perl_module_check.pl simpleMenu.pl
Found 5 modules in simpleMenu.pl
Testing Config: OK
Testing Data::Dumper: OK
Testing FindBin: OK
Testing Strings::IO: NOT INSTALLED
Testing strict: OK


Installing VMWare tools for Debian or Ubuntu

Packages that are required to install VMWare Tools in debian or ubuntu

apt-get install make gcc linux-headers-$(uname -r)

Tagged as: , No Comments

Verifying your Linux Distro is 64bit.

I ran into a situation that I had to verify that I was running a 64bit os. Below is a quick command line check. It checks based on the current kernel loaded.

mrochford@host1:~$ fgrep CONFIG_64BIT /boot/config-`uname -r`


Run a command randomly

I wanted to run a command randomly everyday. Here is a one liner cron that I created.

echo "" | at now + `awk -vu=30 'BEGIN { srand(); printf( "%0.0f\n", rand() * u ); }'` minutes


Moving a directory from one host to another using tar over ssh

tar cf - * | ssh "(cd && tar xf -)"

Tagged as: No Comments

Naigos Plugin: Check for packages to update in Debian/Ubuntu

Over the years I have manages a lot of systems, mostly debian based. The thing I really hate about having a lot of standalone systems is updating software. I am really bad at keeping track of new updates and I really dont want to have a cron script running to send me a email every day. Below is a script I used as a plugin for nagios.

The Script: check_for_updates.pl


Backup of your MYSQL server using mysqldump

Over the years of being a admin I have seen many ideas on how to backup a mysql database server. Many people are satisfied with with one large dump of all databases into one flat text file. Others think copy the actual db files to other locations are the way to back things up. I have found dealing with customer and internal databases you need incremental backups. With all that said I developed a perl script that will log in grab all existing database names and do a mysqldump of each database. It will also keep a specified amount of backups and you also can choose to have some logs gzip'ed or left uncompressed. Below is the link to the code. You will have update login credentials and the ip address of the mysql server.

Link: mysql_backup.pl

Explanation of the script:

The script will login to your mysql server and issue a "show databases;". Once it the database names are retrieved it will run a mysqldump on each database and store the output in the specified directory. The name scheme of the out will be database_name-YYYYMMDD.sql. Doing this it will allow you to sort based on date. Once all mysqldumps have completed it will go through each database directory and audit what should be saved, deleted, gzipped or leave alone. You will be able to chose what the numbers of day you want to retain and the how many days you want to leave as a uncompressed file.