Removing newlines (\n) with sed

Posted on Tuesday, 24th June, 2008 in Life

Today I had to search again on how to remove newline special characters with sed. Thanks to Kamil over at linux.dsplabs.com.au, I found it again rather quickly.

Now, this is just for my own safekeeping, so I don’t end up googling for it again … *shrug*

1
echo -e "Line containing \nnewlines!" | sed ':a;N;$!ba;s/\n//g'

Retiring people

Posted on Wednesday, 28th May, 2008 in Gentoo

I’m not sure whether or not I blogged about this before, but here it is just for me to actually remember what, in which order I need to do. If you got the list in form of a csv file, simply do the following:

1
2
3
4
5
6
$ wget -q http://tinyurl.com/4atkz7 -O - | grep "(" | cut -d'(' -f2 | \
    cut -d')' -f1 | awk '{ print tolower($1) }' > retirements
$ for developer in $( < retirements )
    do retire.py --metadata $developer /cvs/gentoo-x86/ | \
    diffstat > ~/metadata.$developer
    done

That’ll give you a detailed list of which metadata.xml need to be changed.


Rescuing a rebooting machine that’s hanging

Posted on Saturday, 24th May, 2008 in Life

One of my co-worker approached me today with a weird problem. Yesterday he had a disk in a 900GiB array failing which he replaced. After that, he run a rebuild/verification, fsck’ed the file system and tried to mount the volume again.

Apparently the mount produced a kernel oops (guess what, the 900GiB is running reiserfs), thus leaving the kernel tainted (or what do they call it ?). So he tried to reboot the box but it didn’t reboot. It started rebooting but then hung (as in not continuing the reboot). He tried to ssh back to the box, and it worked just fine.

This is where sysrq comes in handy.

1
2
3
4
5
6
# This is gonna activate the sysrq
echo 1 > /proc/sys/kernel/sysrq
 
# Now, since we ain't at a console, we can't use the sysrq keys
# ("b" for reboot, "o" for shutdown)
echo b > /proc/sysrq-trigger

That’ll restart the box, and cha-ching .. :-D