On 04/29/2014 09:22 AM, Sebastian Rückerl wrote:
dd if=$1 of=$2 bs=4M oflag=direct &
dd_pid=$!
control_c (){
echo "Aborting due to interrupt. Disk will most likely be useless."
kill -s KILL $dd_pid
trap - INT
kill -s INT $$
}
#
# trap keyboard interrupt (control-c)
trap 'control_c' INT
while ps ax | grep " $dd_pid " # might also need | grep -v grep here
do
kill -s USR1 $dd_pid
sleep 5
done
The construct with "ps ax | ..." is rather fragile.
I'd use something like the following instead to get
the intermediate I/O statistics:
while kill -s USR1 "$dd_pid" ; do
sleep 5
done
Further note that when dd ends, then the above 'sleep 5'
may extent the time of the script to finish by another
<=5 seconds (which may not be a problem in your case).
Have a nice day,
Berny