Getting a dd progress bar using pv

I neeeded to use dd to blank two IDE disks I have here around. My first problem was to find where to plug those, because I have no box with an IDE bus. Fortunatelly I still keep a FastTrack IDE to PCI board which I could to plug those disks.

After checking their contents I decide to blank them with zeros. I thought, something like this would do the trick:

   dd if=/dev/zero of=/dev/ada1 bs=1M

This command is for FreeBSD, with Linux I’d just replace the disk:

   dd if=/dev/zero of=/dev/sdb bs=1M

However, there’s a problem, dd does not show any progress bar. And so there you are, waiting for the dd command to finish. Here comes pv to the rescue. We can pipe the output of the dd command through pv and then get a progress bar. The output of pv can be piped to another dd instance and write those zerost to the disk.

   dd if=/dev/zero bs=1M | pv | dd of=/dev/ada1

With no commands pv will output the amount of information written (using the best unit, K, M, G) and the speed.

In case we wanted a real progress bar (which will go from 0 to 100%) or an ETA pv would need to know the amount of informatio to be written. In my example, I needed to get the raw space of the target disk, and gpart provides that information.

   dd if=/dev/zero bs=1M | pv --size `gpart list ada1|tail -n 4| grep Mediasize| cut -f 1 -d "(" | cut -f 2 -d ":"`| dd of=/dev/ada1

On Linux I’d do something like this (untested):

   dd if=/dev/zero bs=1M | pv --size `cat /proc/partition | grep "sdb$" |cut -f 3 -d " "` | dd of=/dev/ada1

We would get this:

   18,6GB 0:29:11 [20,3MB/s]] [=====>                       ] 25% ETA 1:21:31

Hope you enjoy this command.

Arrays with the default FreeBSD shell

The default FreeBSD shell is based on the ash shell, which is enough for most tasks. But recently, while adapting the Xen hotplug scripts I discovered it lacks support for arrays.

I needed to somehow trick the default shell and implement a kind of array.

My first thought was to implement a sort of queue using a delimiter and setting the IFS variable to skip that delimiter. That would have provided me a simple FIFO structure, but it wasn’t good enough for what I wanted to accomplish.

I decided to trick sh and use a set of variables whose name contain the index instead. I thought that if I wanted an array named lockdict, why not have a variable named lockdict0, another named lockdict1 and so forth?

The tricky part comes when want to use a loop variable like $i to reference a component of the array. By default The shell won’t expand the value of $i, and we’ll get an error if we try something like this:

 _lockdict$i = "test" 

To workaround this we are going to need our eval friend. If want to assign a value to an index of the ‘array’, we should do something like this:

eval _lockdict$i = "test"

If we want to retrieve the assigned value of the $i component, we should do something like this:

eval temp=\$_lockdict$i

What Jekyll is and why I'm using it

Jekyll is a static site generator, an open-source tool that allows you to build your own site with the hassle of settings a database server and using an scripted language (like PHP, Ruby, Perl, Python or any other you may think of) to run the site.

Instead Jekyll, like a few others, take a different approach. Why not use a generator engine to lay out all the content from static files for you? Why don’t just concentrate on the content and let the site generator do the build?

This is what Jekyll does. It builds a directory hierarchy and sets up a set of files for you. Then, it takes that structure and the files you typed and builds the site for you.

And because you’re just using a bunch of static files with no code at all, means that you don’t need to worry about database security holes, SQL injections or dynamic language security problems. No updates of those pieces of code, you just need to have a web server serving static content and you are ready to go.

Simple, uh? But there’s always a drawback. In this case, there are two:

  1. You lose the usual WYSWYG editor you used in your previous blog engine
  2. You need to find a hosting site for your static files

Instead of having a regular WYSWYG editor, you have to type for files (blog entries, for example) using a simple text editor. The real drawback here is that you need to learn a mark up language (a so simple one though) to do the typing. If I’m not mistaken, Jekyll ships with two converter, Textile and Markdown. I use the latter and I find this cheatsheet very useful.

About the hosting problem, this was also a problem if you wanted to have your own blog engine without any restriction from a blog provider (like having your own wordpress instance anywhere). If you don’t want to mess with a hosting provider, DNS setups and such, you may want to use Dropbox’s public folder or Google Drive. But if you are a programmer comfortable with version control tools and coding in the command line, you may find GitHub pages service very useful.

So these are the reasons why I use it. I find it very useful to just open my vim editor, type something in there and just git-add-push everything to github. I’m fine with a domain like gustauperez.github.io but I know I can create my own domain anywhere and redirect it to GitHub.