Bash one liner to randomize lines in file

October 18, 2007 at 11:57 AM | categories: unix, system administration, linux | View Comments

Discovered that the bash shell has a variable called $RANDOM, which outputs a pseudo-random number every time you call it. Sweet! Allowed me to randomize the lines in a file for a process I needed to do, thusly:

for i in `cat unusual.txt`; do echo "$RANDOM $i"; done | sort | sed -r 's/^[0-9]+ //' > randorder.txt
In other words, put a random number on every line, sort the file, then take off the random numbers. Worked like a charm.
Read and Post Comments

Hivearchive Downtime

October 05, 2007 at 05:45 PM | categories: system administration, linux | View Comments

Had a bit of hardware trouble, with a hard drive failing today. However, due to my sysadmin ninja skills, no data was lost and the RAID 1 is rebuilding.

[root@nexus ~]# cat /proc/mdstat Personalities : [raid1] md1 : active raid1 hdc1[2] hda1[0] 79360960 blocks [2/1] [U_] [>....................] recovery = 2.2% (1809408/79360960) finish=25.9min speed=49725K/sec md0 : active raid1 hdc2[1] hda2[0] 1052160 blocks [2/2] [UU] unused devices:
If you need to do this:
# dd if=/dev/hda of=/dev/hdc bs=512 count=1 # mdadm --manage /dev/md0 --add /dev/hdc2 # mdadm --manage /dev/md1 --add /dev/hdc1
In other words, copy the master boot record from the good drive to the new drive so you have the same partitions, then hot add the new partitions to your array. WARNING DANGER DANGER WARNING. Backup all your data first, and test your backups work. Change the partitions and drives to match your own situation. Failure to do so will cause you to hose your system... That is all. Now if only Linux could do all this automatically like other sane operating systems. Update: I'm getting a little suspicious that just copying the MBR from one hard drive to another, messed up something with Linux's software RAID. Sigh. This is exactly how I would do it in Solaris, but Linux has no great documentation on how to do it easily. Lazyweb? Update, 2 Aug 2008: I did this again and this time realized that copying the MBR will work fine with DD, but Linux needs to be explicitly told to rescan the partition table. I simply opened up the device with fdisk, checked the partitions looked how I wanted and then rewrote the partition table. Fdisk then calls the IOCTL to tell the kernel to rescan the partitions. Problem solved. :)
Read and Post Comments

iPhone fun

September 27, 2007 at 12:22 AM | categories: python, unix, apple, iphone | View Comments

# uname -a Darwin Matt Michie's iPhone 9.0.0d1 Darwin Kernel Version 9.0.0d1: Fri Jun 22 00:38:56 PDT 2007; root:xnu-933.0.1.178.obj~1/RELEASE_ARM_S5L8900XRB iPhone1,1 Darwin # python Python 2.5.1 (r251:54863, Jul 27 2007, 12:05:57) [GCC 4.0.1 LLVM (Apple Computer, Inc. build 2.0)] on darwin Type "help", "copyright", "credits" or "license" for more information. Mmmmm tasty! iPhone with SSH, Python, BSD subsystem. Life is good.

Read and Post Comments

Upgraded to WordPress 2.3

September 25, 2007 at 10:13 PM | categories: wordpress, system administration | View Comments

Surprisingly, the upgrade went pretty smoothly. While dinking around in the admin section, I noticed: Akismet has protected your site from 15,874 spam comments. Man, I hate spammers. The more popular my domains get, the more they get targeted. One of my other sites was used as a forged from address in a bunch of e-mails and I got all the bounces. Thanks for checking SPF everyone. :( Update: Ugh! Damn it.

WordPress database error: [Table 'wp_post2cat' doesn't exist] SELECT cat_ID AS ID, MAX(post_modified) AS last_mod FROM `wp_posts` p LEFT JOIN `wp_post2cat` pc ON p.ID = pc.post_id LEFT JOIN `wp_categories` c ON pc.category_id = c.cat_ID WHERE post_status = 'publish' GROUP BY cat_ID WordPress database error: [Table 'wp_post2cat' doesn't exist] SELECT cat_ID AS ID, MAX(post_modified) AS last_mod FROM `wp_posts` p LEFT JOIN `wp_post2cat` pc ON p.ID = pc.post_id LEFT JOIN `wp_categories` c ON pc.category_id = c.cat_ID WHERE post_status = 'publish' GROUP BY cat_ID
Yes, I ran the update which supposedly updated my DB. Lovely. Update 2: Apparently I need to update my Google Sitemaps plugin as found in this thread: http://wordpress.org/support/topic/135564
Read and Post Comments

VMWare VProbes (dtrace for all)

September 17, 2007 at 07:07 PM | categories: software, virtualization, system administration, troubleshooting | View Comments

Keith Adams has an intriguing post about VMWare vprobes:

VProbes attempts to provide a set of tools for answering the question, "What the heck is this computer doing?" It's an open-ended question, so vprobes is accordingly open-ended, as well. In its current form, it provides an interactive, safe way of instrumenting a running VM at any level: from user-level processes down to the kernel, and even into VMware's VMM and hypervisor, if need be.

First, we are aiming to provide a Dtrace-like tool for other commercially important operating systems than Solaris. Second, VProbes can combine with other virtualization-based techniques in powerful ways. For example, VProbes and deterministic replay combine to make the most potent tool that I'm aware of for debugging intermittent performance anomalies.

Read and Post Comments

Ruby Monkey Patching Slang

August 12, 2007 at 11:36 AM | categories: humor, ruby | View Comments

Stumbled across a great list of "alternate" terms for Monkey Patching in Ruby: My Complete List Of Substitute Names For The Maneuver We Now Know To Be Monkeypatching

Read and Post Comments

TCP/IP Over Firewire on OSX

July 22, 2007 at 10:26 AM | categories: grid computing, osx, network | View Comments

I wasn't aware of this until today:

Customers can immediately enable IP over FireWire and then connect two or more Macintosh systems by FireWire for file sharing, Internet sharing, or the use of any other IP-based service. IPv6 and zero-configuration networking are also supported. Many Macintosh products have 10/100 Ethernet and FireWire 400, making FireWire the fastest option for local area IP. For help activating IP over FireWire, open Mac Help and enter "IP over FireWire". IP over FireWire can also be used as the starting point for new development, such as for cluster computing applications. Established IP services such as AFP, HTTP, FTP, SSH and TCP/IP can all be used on FireWire to support new development.
IP Over Firewire (apple.com)

Sweet! (yes, Gigabit Ethernet is faster and better supported, but I love having a wide range of devices on the Physical layer of the stack)

Read and Post Comments

« Previous Page -- Next Page »