So, my son asked me yesterday about how computers work, and we finally got to binary, which he had heard about in school. Then he asks me how numbers look like in binary, and stuff like that. Instead of looking them up, I came up with a perl script to show him any number he would want to see in binary. It’s nothing earth-shattering, but I thought someone may want get a kick out of it, and it really shows how powerful perl is. So, here goes:

#!/usr/bin/perl -w

use strict;

# Get the number from the command line or use default.
my $number = shift || 42;

printf "%b\n", $number;

bash prompts….

…I use.

My regular bash PS1:
export PS1='\[\e[0;32m\]\u\[\e[m\] \[\e[1;34m\]\w\[\e[m\] \[\e[1;32m\]\$\[\e[m\] \[\e[1;37m\]'

My “fancy” bash PS1 for Linux:
export PROMPT_COMMAND='history -a;echo -en "33[m33[38;5;2m"$(( `sed -n "s/MemFree:[\t ]\+\([0-9]\+\) kB/\1/p" /proc/meminfo`/1024))"33[38;5;22m/"$((`sed -n "s/MemTotal:[\t ]\+\([0-9]\+\) kB/\1/Ip" /proc/meminfo`/1024 ))MB"\t33[m33[38;5;55m$(< /proc/loadavg)33[m"'
export PS1='\[\e[m\n\e[1;30m\][$$:$PPID \j:\!\[\e[1;30m\]]\[\e[0;36m\] \T \d \[\e[1;30m\][\[\e[1;34m\]\u@\H\[\e[1;30m\]:\[\e[0;37m\]${SSH_TTY} \[\e[0;32m\]+${SHLVL}\[\e[1;30m\]] \[\e[1;37m\]\w\[\e[0;37m\] \n($SHLVL:\!)\$ '

Processes by uid in perl.

This is just a quick hack to find which uid owns how many processes on your system. Obviusly, this can be altered to just about anything, but it’s a good example of how perl can use Unix commands inside a script.

#!/usr/bin/perl -w

# Who owns how many processes

@pslist = qx/ps -ef/;

# Remove the header line
shift @pslist;

foreach $line (@pslist)
@splitline = split(" ",$line);
# Count usernames

foreach $user (sort keys (%count))
print "User $user owns $count{$user} processes \n";

Mirroring a ZFS root pool.

A quick guide to mirror a ZFS root pool:

1. Attach the new device to your root pool:
# zpool attach

2. Install the bootblock on the new device:
# installgrub /boot/grub/stage1 /boot/grub/stage2

# installboot -F zfs /usr/platform/`uname -i`/lib/fs/zfs/bootblk

3. Make sure your OS of choice knows about this. On Sparc you need to add the device to the OBP variable “boot-device”, and on x86 to the BIOS settings.

ZFS/zpool problems during boot.

Every now and then ZFS/a zpool can have problems during boot time, and here’s a way to solve them.

ok boot -m milestone=none
# mount / as writeable
/sbin/mount -o rw, remount /
# Remove or move the zpool cache, so ZFS "forgets" that zpools exist on this system
rm /etc/zfs/zpool.cache
# Determine which pools may have problems with
fmdump -eV
# boot to
svcadm milestone all
# then import the pools one by one, but skip the ones with reported problems
zpool import

This should get you on your way, and if all else fails rtfm. 😉