Nerd Notes

/dev/brain: no space left on device

Archive for the ‘CLI’ Category

Cancellare le directory .svn

with one comment

Quando bisogna pulire una working directory locale ottenuta da un checkout fatto su un repository subverison, è sufficiente un

$ find -d . -type d -name .svn -exec rm -rf {} \;

lanciato nella directory principale del checkout. Occhio all’opzione -d: serve a fare in modo che l’albero delle directory venga attraversato a partire dalle foglie. Senza il -d verrebbero visualizzati degli errori nell’esecuzione di alcune istanze di rm -rf.

Update (20120417): se il tuo scopo è ottenere una copia pulita da un repository o una working copy, probabilmente dovresti guardare il comando export di svn.

Written by Mirko Caserta

September 9, 2011 at 2:01 pm

Posted in CLI

Tagged with , , , , ,

Backing up a vmware virtual machine

with 5 comments

I’ve learnt quite a number of new things today. One of these things is that an ISO9660 filesystem doesn’t allow files bigger than a couple of gigabytes. Another thing is that bzip2 kicks ass, even if it actually doesn’t implement the best compression algorithm available today (your milage may vary).

Another interesting thing is that the good old cdrtools package on Gentoo sucks. In my understanding that’s mainly because of licencing issues which came out during the software development. But, no worries, the new cdrkit ebuild has a modern cdrtools implementation with a compatible interface. That is, the good old mkisofs and cdrecord command lines you (and your GUIs) had learnt how to use are just the same. Different software, same interface. Great, uh? So, first of all, if you want the latest tools on a Gentoo box, you’ll need to:

# emerge -C cdrtools
# emerge -av cdrkit

Anyway, my job today was to backup on DVD-R media a large vmware virtual machine in order to regain free storage space on a server with serious shortage troubles. To begin with, we have a directory which holds the VM (virtual machine) files:

# du -sh my-very-cool-vm
21G my-very-cool-vm

Now, 21 gigabytes of data is a lot because this VM hosts a few extra virtual disks. But, if you’re lucky enough like me, some bzip2 goodness might help:

# tar cvf - my-very-cool-vm | \
bzip2 --compress --verbose --best --stdout > \
my-very-cool-vm.tar.bz2
# ls -lh my-very-cool-vm.tar.bz2
total 4.3G
-rw-r--r-- 1 root root 4.3G Mar 8 15:32 my-very-cool-vm.tar.bz2

Depending on your iron, the time between tar and ls might be enough for you to gain a few extra golds in World of Warcraft. Anyway, now that might actually fit on a DVD-R. But, since there’s a 2GBytes file size limit on ISO9660 filesystems, we still need to do a little something before we can fire up mkisofs. Our old unix friend split comes to the rescue:

# split -b 1024m -d my-very-cool-vm.tar.bz2 \
my-very-cool-vm.tar.bz2-part-
# rm my-very-cool-vm.tar.bz2
# ls -lh
total 4.3G
-rw-r--r-- 1 root root 1.0G Mar 8 16:04 my-very-cool-vm.tar.bz2-part-00
-rw-r--r-- 1 root root 1.0G Mar 8 16:05 my-very-cool-vm.tar.bz2-part-01
-rw-r--r-- 1 root root 1.0G Mar 8 16:05 my-very-cool-vm.tar.bz2-part-02
-rw-r--r-- 1 root root 1.0G Mar 8 16:06 my-very-cool-vm.tar.bz2-part-03
-rw-r--r-- 1 root root 295M Mar 8 16:06 my-very-cool-vm.tar.bz2-part-04

This is just perfect. Assuming the above files are in a directory called mydir, I can now run mkisofs like this:

# mkisofs -o dvd.iso -r mydir

This creates a file which holds the ISO9660 filesystem that we can later feed to cdrecord. My peculiar incantation for cdrecord is as follows:

cdrecord -v dev=/dev/hdc driver=mmc_mdvd -sao dvd.iso

Written by Mirko Caserta

March 8, 2007 at 4:54 pm

Struttin’ from the CLI

leave a comment »

Suppose you want to write a shell script that calls every action in your struts-config.xml in order to, say, stress test every callable url in your application.

Assume you have the following struts-config.xml:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<action-mappings>
<action
path="/page1"
forward="/WEB-INF/page/page1.jsp"/>
<action
path="/page2"
forward="/WEB-INF/page/page2.jsp"/>
</action-mappings>
</struts-config>

The point here is that you want to extract the path attribute value for each action and complete it with a full blown URI. You could do that with a lot of grep and/or awk or you could just use xmlstarlet. So, go now, download a copy and install it, or fire up your favourite package manager (be it apt-get, synaptic, portage or whatever) and let it do the job for you.

Once you have xmlstarlet installed, just do:

$ xmlstarlet sel -t -m "/struts-config/action-mappings/action" \
-o http://localhost/ctx -v "@path" -o .do -n struts-config.xml

and you should get the following output:

http://localhost/ctx/page1.do
http://localhost/ctx/page2.do

This basically means that you can, for instance, use wget to grab all those URIs:

$ xmlstarlet sel -t \
-m "/struts-config/action-mappings/action" \
-o "wget http://localhost/ctx" \
-v "@path" \
-o .do -n \
struts-config.xml | sh

This will fire up wget for each action path in the struts-config.xml. Neat, uh?

Under the hood, xmlstarlet is simply using some xslt transformation on the xpath expressions given in the above template to do its work. So, in case you want to sharpen your xml tools, you’ll need to get a better understanding of xpath at least, since it has to be used in the select templates.

Written by Mirko Caserta

November 15, 2006 at 3:34 pm

Posted in CLI, struts, XML

UNIX time to human readable

with one comment

The current issue of the Gentoo Weekly Newsletter has a good clue on how to easily convert a date from the standard UNIX time format (which basically is a number which represents the number of seconds elapsed since January 1, 1970 at midnight, UTC) to a human readable form. The best solution is using date -d on Linux systems such as in:

$ date -d @1161911504
Fri Oct 27 03:11:44 CEST 2006

However, on BSD derived systems, such as Mac OS X (and maybe Solaris), date -d won’t work so you have to used instead:

$ date -r 1161911504
Fri Oct 27 03:11:44 CEST 2006

Written by Mirko Caserta

November 1, 2006 at 8:10 pm

Posted in CLI, Console, Linux, UNIX

Making vim syntax highlighting usable

with 13 comments

Someone says vi vi vi is the editor of the beast. He’s right. That’s why I use vim, which is a modern editor, backwards compatible with vi and full of bells and whistles. But, most of all, vim gets things done for me. I’m in love with vim.

On some modern linux distributions, vim comes with syntax highlighting enabled by default. Since you’re a die-hard nerd like me, your terminal window colors scheme is like god meant it to be: with a black background. And, if you really feel nostalgic like me, you may even have gone one step further and you’ve setup green as the foreground color. That’s great, but there’s one thing that makes vim syntax highlighting suck on such a color scheme: it was meant by default to work on a light (read white) background.

My colleagues hate vim’s default color highlighting and they’re tempted all the time to use the old beast: vi, just because it has no color syntax highlighting which makes comments unreadable to say the least. This should get fixed. Enter the gay world with: set background=dark That means, while in vim, enter command mode and type the above command.

Great! The world has suddenly become clearer and you feel an urge to dance to the rhythm of Village People’s YMCA. That is, until you close vim and open it again. Then you’re into Robert Smith mode again. Too bad. We’ve got to fix that too. The recipe is as easy as editing your ~/.vimrc or, better yet, making the change system wide by editing the /etc/vim/vimrc file and adding a couple lines:

syntax on
set background=dark

That’s it. Now, where’s my biker dress?

Written by Mirko Caserta

October 27, 2006 at 7:48 am