Browsing the mind category...






#!/bin/bash
#Simple Database Backup and Rotation Utility
#Run from crontab nightly as root
#00 0    * * *   root    /root/bin/dump-dbs.sh
 
 
DATE=`date +%Y%m%d-%a`
DBS=`mysql -e "show databases" | awk '{ print $1 }' | tr '\n' ' ' | cut -b10-`
 
 
#Where to store your .sql backups
cd /root/MySQL-Backup
 
 
#Remove Previous Week's Backup
rm -f *-`date +%a`.sql
 
 
for i in $DBS ;
    do mysqldump --opt --allow-keywords --quote-names --result-file=$i-$DATE.sql $i;
done



I found this Perl one-liner here today. It’s a work of art.

du -k | sort -n | perl -ne 'if ( /^(\d+)\s+(.*$)/){$l=log($1+.1);$m=int($l/log(1024));printf  ("%6.1f\t%s\t%25s  %s\n",($1/(2**(10*$m))),(("K","M","G","T","P")[$m]),"*"x (1.5*$l),$2);}'





#!/bin/bash
#Show status for bonded IPs currently listed in /etc/ha.d/haresources
 
#We only want the second word (seq +2) through to the final four
#words (seq -4) in our haresources
cnt=`wc -w /etc/ha.d/haresources | cut -d" " -f1`
acnt=$(echo " $cnt - 4 " | bc -l)
 
addr=$(for i in `seq 2 $acnt` ;
do /bin/cat /etc/ha.d/haresources | cut -d" " -f$i | tr '\n' ' ' ;
done)
 
y=$(for x in $addr;
do echo $x | sed 's/IPaddr:://' ;
done)
 
for z in $y;
do echo " " ;
echo "Status for $z";
/etc/ha.d/resource.d/IPaddr2 $z status ;
done
 
echo " "
echo "Completed status for $acnt bonded address"
echo " "





Wrote this python code to assist in updating Wordpress versions via SVN. The .py script, called update-wp.py, simply sits under your DocumentRoot folder. In this case, I have the directory set to www. Note that you must have installed your original Wordpress version using the SVN checkout command for any of this to work. More on that can be found here.

#!/usr/bin/python
#Update Wordpress from SVN
#Michael Bevilacqua 3/7/2009
 
import sys, subprocess
 
if len(sys.argv) < 2:
    print 'Please input version to update too (ie. 2.7.1)'
    sys.exit()
 
if sys.argv[1].startswith('--'):
    option = sys.argv[1][2:]
    # fetch sys.argv[1] but without the first two characters
    if option == 'version':
        print 'Version 1.0 3/7/2009 Michael Bevilacqua'
    elif option == 'help':
        print '''\
 
This program will update the Wordpress installation
in www to the latest version that you must specify
as the first argument like so:
./update-wp.py 2.7.1
 
You can find a list of Wordpress versions by browsing
to http://svn.automattic.com/wordpress/tags/
 
Options include:
--version : Prints the version number
--help    : Display this help'''
 
    else:
        print 'Unknown option.'
        sys.exit()
    else:
 
        version = sys.argv[1]
 
        print "Updating Wordpress installation in www to version %s" % version
 
        svn = 'svn sw http://svn.automattic.com/wordpress/tags/%s/ www/' % version
 
        subprocess.call(svn, shell=True)
 
        print ""
        print ""
        print "Please run wp-admin/upgrade.php to complete this update."