Friday, March 04, 2005

De Morgan's Theorem...

Does logic do your head in?


if(!condition1 | !condition2) equals if(!(condition1 & condition2))

And

if(!condition1 & !condition2) equals if(!(condition1 | condition2))

Perl multi-line match...

davis gave me the answer nicely...


#!/usr/bin/perl

use warnings;
use strict;

local $/;
$_ = <DATA>;

$_ =~ s/<table>\n<tr>/<!-- TABLE START -->/i;

print;

__DATA__

<TABLE>
<TR>
<TD>



And also added:

you can ignore leading spaces with:


$_ =~ s/\s*]*>\n\s*/\n/ig

Wednesday, March 02, 2005

Missing header files...


$ make hello
cc hello.c -o hello
hello.c:1:19: stdio.h: No such file or directory
hello.c:2:20: unistd.h: No such file or directory
hello.c: In function `main':
hello.c:89: error: `stdout' undeclared (first use in this function)
hello.c:89: error: (Each undeclared identifier is reported only once
hello.c:89: error: for each function it appears in.)
make: *** [hello] Error 1

# apt-get install libc6-dev

Hello, world!

:o)
(humming "the stripper"):

#!/bin/bash
/usr/bin/strip --remove-section=.comment --remove-section=.note --strip-all $@

Thursday, February 17, 2005

Need to update all of the CPAN modules on a server?

If you are using the CPAN module within Perl, you can update all of the installed modules on your system using the command:


perl -MCPAN -e 'CPAN::Shell->install(CPAN::Shell->r)'


This forces CPAN to produce a list of all of the outdated modules on the machine and install them in one hit...

Not recommended for your average joe. you'll have to go over all of your module dependecies and check to see if updates break any of your live code.. still though there are instances where this can be useful.

Something else to think about... have a look here:


lrwxrwxrwx 1 root root 5 Feb 5 21:36 /usr/lib/perl/5.8 -> 5.8.4
drwxr-xr-x 5 root root 4096 Jan 30 2004 /usr/lib/perl/5.8.2
drwxr-xr-x 4 root root 4096 May 4 2004 /usr/lib/perl/5.8.3
drwxr-xr-x 30 root root 4096 Feb 17 18:05 /usr/lib/perl/5.8.4
drwxrwsr-x 9 root staff 4096 Mar 7 2002 /usr/local/lib/perl/5.6.1
drwxrwsr-x 21 root staff 4096 Dec 5 2003 /usr/local/lib/perl/5.8.0
drwxrwsr-x 4 root staff 4096 Oct 30 2003 /usr/local/lib/perl/5.8.1
drwxrwsr-x 11 root staff 4096 Mar 25 2004 /usr/local/lib/perl/5.8.2
drwxrwsr-x 12 root staff 4096 Jan 23 10:59 /usr/local/lib/perl/5.8.3
drwxrwsr-x 27 root staff 4096 Feb 17 18:08 /usr/local/lib/perl/5.8.4


On a box where Perl has been upgraded a few times there will be lots of old dirs with modules in...

Wednesday, February 16, 2005

Don't need patch...

If you don't have patch installed on a machine it's OK...

You can still use diff to update files...

To update a file using diff & ed:


# (diff -e file1 file2 ; echo -e "w\nq" ) > diffs
# ed file1 < diffs


Bear in mind that it has no context, so it doesn't know where it is in a changed file, it just goes by absolute line number (which means you have to update the bottom of the file before you can update the start - if you're only taking across some of the changes then you need to start at the bottom of the file and work your way back, only updating a chunk at a time... also it's not reversable... patch can see if you're trying to run a patch in reverse... if you try running ed to apply a patch, but accidentally run it against the updated file... then you will really mess it up!

so... make a backup (easy for me to say!) and be CAREFUL!

Tuesday, February 15, 2005

cpio pass-through mode

You have a web directory with 100000 files in it on a DVD.

You want to get a copy of all of the .htm files for editing...

find webdir/ -name "*.htm" | cpio -vdump /target/directory

(-a resets access times on source files, but no point using that on a DVD!)

The letters vdump can go in any order... more logically "padmuv", but "vdump" will be nice to remember! :o)

# tar cvf /target/directory/backup.tar $(find webdir/ -name "*.htm")
-su: /bin/tar: Argument list too long

# find webdir/ -name "*.htm" | wc -l
100810

Monday, February 07, 2005

Installing Debian from hard disk...

http://d-i.pascal.at/
http://people.debian.org/~joeyh/d-i/images/daily/hd-media/

http://www.debian.org/devel/debian-installer/ports-status

http://www.debian.org/devel/debian-installer/

Sunday, February 06, 2005

If you want to reinstall everything...

You could do this:


apt-get -u --reinstall --fix-missing install $(dpkg -S LC_MESSAGES | cut -d: -f1 | tr ', ' '\n' | sort -u)


Tip of the day...

When you get Error 17 from grub it means it cannot find the partition you want it to boot...


GRUB Loading stage 1.5

GRUB loading, please wait....
Error 17


(ToDo: go back and check this, I got this message off the web, but it looks right)

The tip is...
be careful if you go using:


hide (hd0,0)


Because when you hide partitions it changes their partition type, and if you hide the one with the grub install in it (e.g. where your /boot is) then grub won't be able to access the menu.lst to know what to boot!