Tech & Toys
-
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>
-
Samba 3 and apostrophes in computer description
If you have an apostrophe in XP’s Computer Description field then the computer will not be recognised as part of the samba domain despite it having joined properly.
This is in samba 3.0.2a untested in more recent versions as yet.
-
PCI device 1283:8212 (Integrated Technology Express, Inc.)
My friend recently got an ATA133 card with this chipset on it. The full proc/pci entry looks like:
RAID bus controller: PCI device 1283:8212 (Integrated Technology Express, Inc.) (rev 17). IRQ 10. Master Capable. No bursts. Min Gnt=8.Max Lat=8. I/O at 0xdcd8 [0xdcdf]. I/O at 0xdcd0 [0xdcd3]. I/O at 0xdcc0 [0xdcc7]. I/O at 0xdcb8 [0xdcbb]. I/O at 0xdca0 [0xdcaf].
If you want to use this under linux you need to compile in the driver as detailed under the title **IT8212F
ATA133 RAID Controller** on this page (Broken link ~~http://www.ite.com.tw/software_download/software_download2.asp~~). To compile up the driver you need to enable scsi in your kernel and link /usr/src/linux-2.4 (or linux-2.6 depending on kernel version) to wherever your linux source tree is. If you are using modules remember to modprobe both scsi and sd_mod.
You then put the created iteraid.o file into
/lib/modules/<i>kernel-version</i>/kernel/drivers/ide/pci/
making directories if you have to.
-
Lookupd
while trying to fix lookupd hanging I found this (Broken link
http://www.macwrite.com/criticalmass/ten-more-mac-os-x-loose-ends-part-2-pf.php) little page which explains some stuff about how to change the order etc.
-
Perl timeouts
Some perl that sets a timeout value
#!/usr/bin/perl $SIG{ALRM} = sub { alarmed(); }; alarm(20); eval { check_whatever; }; alarm(0); sub check_whatever() { # stuff to do that might timeout exit 0; } sub alarmed() { # stuff to do after the alarm has gone off. exit 1; }
Thanks to Timbo for help with this…
-
Using Open SSL with WS/AS
CA.pl -newca and follow prompts
CA.pl -signreq (req from WS/AS needs to be call newreq.pem)
output is newcert.pem, this goes back to WS/AS
needs gcc libs to work
-
Monitoring Apache
Found this nice page with scripts and configs for parsing the apache
server-status
page and using mrtg to graph them