Tech & Toys
-
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.
-
OS X filesystem case insensitivity problems
I’m using os X (10.3.3) to serve images via apache here and have just been bitten by the lack of case sensitivity on the filesystem. I had a
LocationMatch
block inhttpd.conf
which was not as secure as I expected:<LocationMatch "/.*/hires/.*"> <Limit GET> Satisfy any Order deny,allow Deny from all Allow from XX.XX.XX.XX </Limit> </LocationMatch>
This was obviously meant to stop access to a
hires
directory, however because of the lack of case sensitivity if you tried to grab the same url but withHIRES
instead it would fail to match this regex but it would still match thehires
directory. To fix this I have changed the regex to:<LocationMatch "/.*/(H|h)(I|i)(R|r)(E|e)(S|s)/.*"> <Limit GET> Satisfy any Order deny,allow Deny from all Allow from XX.XX.XX.XX </Limit> </LocationMatch>