How to get a status update out of a running dd process on Linux

With dd running in a terminal, open a new terminal to the server and send the USR1 signal to the dd process. You can either do this by looking up the process ID and doing:

  1. kill -USR1 pid_here

Or use killall to send the signal to all dd processes:

  1. killall -USR1 dd

You’ll see output similar to this in the terminal dd is running in:

  1. 45900+0 records in
  2. 45900+0 records out
  3. 752025600 bytes (752 MB) copied, 541.855 s, 1.4 MB/s

 

Tags: , , ,

How to securely copy data over SSH

This is a really useful tip, and it has infinite uses in a *nix environment. You can pipe data over SSH, from both a client and a server, and process it on the other side. This is pretty useful as it avoids the requirement to have the hard disk space to store a file before it is imported. Here’s a few examples:

Copying a remote database to a local database

  1. ssh user@server-domain.com 'mysqldump -u root --password=passwordhere remote-database-name-here | gzip -c' | gunzip | mysql -u root --password=passwordhere local-database-name-here
You’ll see  that we can pass a command as the 3rd parameter of ssh. This is executed on the remote end. Here, we take the output of mysqldump, gzip it and send it over SSH. We pipe the ssh command into gunzip to decompress it and finally pipe that into the local mysql command to import it.

 

Copying a folder of files to a remote server

  1. cd /path/to/dir/to/copy;
  2. tar -cz . | ssh user@server-domain.com 'tar -C /path/to/remote/dir -xzv'
In this example, we cd into a directory on the local machine, create a tar of its contents and pipe this over ssh into a reverse tar command on the remote server. The z flag on the tar commands gzips/ungzips the output for you, automagically. Note that this won’t include the root directory – i.e. it’ll transport  /path/to/dir/to/copy/* to  /path/to/remote/dir.

 

The two examples above have shown you using ssh on the left and right of the command. There’s plenty of other uses, see what you can do with it.

Quick Fix: Filesystem notification initialization error — contact your mail administrator (check for configuration errors with the FAM/Gamin library)

This error can be seen in your mail client and is often caused by Courier. If you are the system administrator of the mail server, simply install libgamin as follows:

If you are root:

apt-get install gamin

If not:

sudo apt-get install gamin

Restart all of your courier services as follows (requires you to be using bash shell):

If you are root:

find /etc/init.d/ | grep courier | while read line; do $line restart; done

If not:

find /etc/init.d/ | grep courier | while read line; do sudo $line restart; done

Raspberry Pi – $25 computer with a huge amount of potential

Raspberry Pi – $25 computer with a huge amount of potential

I’ve just stumbled across the Raspberry Pi (RasPi) and have spent the past 3 hours contently reading about it and the Gertboard. In a nutshell, RasPi is a credit card sized computer with USB, HDMI, composite and analogue audio I/O ports – all powered by a 600MHz Broadcom ARM processor and 128MB RAM – selling for $25. There’s a $35 “B” model which, as I understand it, has 256MB RAM and an Ethernet port. An SD card reader provides permanent storage for the device.

The RasPi beta boards have been shown to successfully run Linux and are set to be the core of a host of home-brew devices performing a variety of tasks. The boards can compile and run high level programming languages and would be perfect to teach programming to school kids and individuals alike.

However, the thing that interested me most was Gertboard. This is a programmable expansion board for the RasPi. It was created by Broadcom Engineer Gert van Loo and has been designed to teach both electronics and low level programming. In another nutshell, it allows the programming and control of motors, relays, LEDs, etc. I have personally dabbled with electronics (with little success) and this is something that really interests me. I half wish I did electronics as a degree rather than spending 3 years learning very little of real value on a Computer Science course. I dabbled with low level programming in the form of Intel 8086 compatible assembly language whilst at University and I quite enjoyed this also.

I rarely jump on anything shiny and new, eagerly anticipating its release; however the RasPi and Gertboard have gotten my attention and I will be sure to pick some up when they’re released.

Using ImageMagick to create thumbnails for the web

You can use ImageMagick’s convert tool to resize images on the command line in a Linux, BSD or Windows environment.

The syntax is thus:

  1. convert "/path/to/original.jpeg" -scale 150x150\> -quality 50% -unsharp 1x3+1+.1 -sampling-factor 1x1 -strip "/path/to/new.jpeg"

This breaks down as follows:

  • -scale Resize the image to 150×150 pixels if the image is already larger than that size (as signified by the >). This will not distort the image – rather scale it such that at least one side is 150px.
  • -quality Decrease the JPEG quality by 50% of the original to reduce the file size
  • -unsharp Sharpen the image after resize
  • -strip Strip the profile information. This is important if you don’t require this info in the resized image as I have seen it reduce a 500KB image to 8KB.

Here’s an example of using this to recursively resize all of the images in a directory:

  1. cd /path/to/original/dir; find | grep -i jpg$ | while read line
  2. do
  3. if [ ! -d "`dirname "../JJ-products-2011-12-19-thumbs/$line"`" ] ; then
  4. mkdir -p "/path/to/new/dir/`dirname "$line"`";
  5. fi;
  6.  
  7. convert "$line" -scale 150x150\> -quality 50% -unsharp 1x3+1+.1 -sampling-factor 1x1 -strip "/path/to/new/dir/`dirname "$line"`/`basename "$line"`";
  8. done

The full manual is available here: http://www.imagemagick.org/script/command-line-options.php#profile and here: http://www.imagemagick.org/Usage/resize/#scale

ImageMagick does an awful lot more than this, so check out the manual.