View output of the dd command

Recently whilst wiping some old hard disks I thought it would be useful to see what the ‘dd’ command was doing, rather than sitting there blankly for hour. I knocked up a little bash script to run in another terminal that will update the terminal running dd with some useful status information.

In this example, dd will be run as…

$ dd if=/dev/random of=/dev/sda

copy the following into ddUpdate.sh for example and run it…

#!/bin/sh
 
ddpid=`ps auwx | awk '/dd if/ && !/awk/ { print $2}'`
 
while [ "$ddpid" != "" ]
do
kill -USR1 $ddpid
sleep 1
ddpid=`ps auwx | awk '/dd if/ && !/awk/ { print $2}'`
done

This outputs the following to the terminal running dd…

xxxxxx records in
xxxxxx records out
xxxxxx bytes (xx nn) copied, xxxx s, xx MB/s