• Partitioning >1Tb volumes

    If you need to create partitions on a disk (or raid volume) which is larger than 1Tb you will need to use parted and set the disk label to GPT. This is an example session creating 2 1Tb partitions on a 2Tb raid5 volume:

    [root@sn-b03 parted]# parted /dev/sdb
    GNU Parted 1.6.9
    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation,
    Inc.
    
    This program is free software, covered by the GNU General Public License.
    
    This program is distributed in the hope that it will be useful, but WITHOUT ANY
    WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
    License for more details.
    
    Using /dev/sdb
    Information: The operating system thinks the geometry on /dev/sdb is 291775/255/63.
    Therefore, cylinder 1024 ends at 8032.499M.
    (parted) mklabel gpt
    (parted) mkpart primary 0 1048576
    (parted) mkpart primary 1048577 2097152
    (parted) p
    Disk geometry for /dev/sdb: 0.000-2288754.000 megabytes
    Disk label type: gpt
    Minor    Start       End     Filesystem  Name                  Flags
    1          0.017 -1048576.000  ext3
    2     -1048575.000      0.000
    (parted) quit
    Information: Don't forget to update /etc/fstab, if necessary.
    
    [root@sn-b03 parted]#
    


  • Where am I?

    If you are writing a bash script and you need to know where you are you can use this:

    #!/bin/sh
    
    # always prints out the directory in which this script is lives
    # no matter where it is run from
    
    # doesnt cope with ../bin/script.sh, which should be ./script.sh anyway
    
    bn=`basename $0`;
    echo $0 | grep "^/" > /dev/null 2>&1
    
    if [ $? -eq 1 ]; then
     echo $0 | grep "^\.\/$bn" > /dev/null 2>&1
     if [ $? -eq 1 ]; then
       echo case 1 - relative ref
       here=`dirname $PWD/$0 | sed 's/\.\///'`
     else
       echo case 2 - local ref
       here=$PWD
     fi
    else
     echo case 3 - root ref
     here=`dirname $0`
    fi
    
    echo script home is $here
    

    Thanks to Justin for this


  • zaphod

    Bits inside my pc…


  • Configuring mail clients to filter on a X-header

    found this nice page which details how to configure various mail clients to filter on a given X-header. Uses for this would be to filter on the X-Spam-Flag: YES header that SpamAssassin adds to mail


  • CDROM sub folders empty when they shouldnt be

    I was recently setting up a Jumpstart server and when I ran the setup_install_server script in Solaris_9/Tools I was getting:

    ERROR: /cdrom/sol_9_sparc/s0/Solaris_9/Tools/Boot is not a valid install boot image<br /> Check that boot image is valid, or use [-t]<br /> to specify a valid boot image.

    The solution is to restart the vold service which can be done with a simple:

    # /etc/init.d/volmgt stop<br /> # /etc/init.d/volmgt start

    Thanks to Nicholas for pointing this out to me.


  • Perl goodies

    Found these two nice links this morning, first a very nice periodic table of perl operators and second, a useful little cgi that helps find out what is installed on your server.


  • 300 most common english words

    needed this for something I was working on, so though I would leave it here (Broken link http://usefulthings.org.uk/files/common-english-words.txt)


  • Setting a variable in bash if it is not defined

    Update: An anonymous commenter pointed out that bash has the ability to do this in a much shorter way:

    BLAH=${BLAH:-no}
    

    Job done!, my original older way is below…

    [root@sn-b02 init.d]# echo $BLAH
    
    [root@sn-b02 init.d]# [ "${BLAH}" = "" ] && export BLAH="no"
    [root@sn-b02 init.d]# echo $BLAH
    no
    [root@sn-b02 init.d]#
    


  • return codes

    When running a command in bash it will store the return code in the special variable $?, like this:

    [robin@book robin]$ ls -ld tmp
    drwxr-xr-x  3 robin  robin  1024 Aug  3 11:02 tmp
    [robin@book robin]$ echo $?
    0
    [robin@book robin]$ ls -ld bob
    ls: bob: No such file or directory
    [robin@book robin]$ echo $?
    1
    [robin@book robin]$
    

    When running a series of commands in a pipe however it is sometimes necerssary to find the return code of an individual command in the pipe, in this case bash stores the return codes in an array names $PIPESTATUS which you can access like any other bash array. The array can only be used once however, so if you want to use it more than once store it in some other temporary array.

    [robin@book robin]$ echo "tmp"  | xargs ls -ld
    drwxr-xr-x  3 robin  robin  1024 Aug  3 11:02 tmp
    [robin@book robin]$ echo ${PIPESTATUS[@]}
    0 0
    [robin@book robin]$ echo "bob"  | xargs ls -ld
    ls: bob: No such file or directory
    [robin@book robin]$ echo ${PIPESTATUS[@]}
    0 1
    [robin@book robin]$ echo "bob"  | xargs ls -ld
    ls: bob: No such file or directory
    [robin@book robin]$ echo ${PIPESTATUS[1]}
    1
    [robin@book robin]$
    


  • Making iDVD use an external dvd writer

    I recently bought one of these fantastic Lacie drives. The problem is that iDVD will not let me write to anything other than a superdrive. Then I found this thread. Download the file from there (mirrored here (Broken link http://usefulthings.org.uk/files/HPfurz.sit)) extract the archive and place the 2 files in your home account. Control click on either the burn dvd button or the burn dvd menu item and it should present you with a list of dvd writers attached to the machine, or the option of writing to a img file.