[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Problem using dd within bash script
From: |
Bernhard Voelker |
Subject: |
Re: Problem using dd within bash script |
Date: |
Tue, 29 Apr 2014 09:44:55 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 |
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
Re: Problem using dd within bash script, Bernhard Voelker, 2014/04/28