[NTLUG:Discuss] Bash Shell Script
kbrannen@gte.net
kbrannen at gte.net
Tue Aug 19 22:07:41 CDT 2003
Wilson, David wrote:
> I am new to shell scripting and need a little assistance. I am trying to
> write a script that will copy a hard drive with dd in 640mg chunks. I plan
> on using a loop to accomplish this however I would like the condition of the
> loop to terminate when dd reports an error.
>
> For example, script will have dd skip a variable number of blocks, count a
> number of blocks, write out to an incrementing file and then repeat. When
> dd gets to the end of the drive, it should stop.
>
> Currently, I have to calculate the size of the drive in 512b blocks and then
> use that value for determining when to stop copying.
>
> suggestions?
Why go to all that trouble? Just let dd do its thing. Or check out the
"split" utility.
If you must write a script, you'll end up with something like:
#!/bin/bash
FILESIZE= #you said you already have this
WRITTEN=0
INC= #increment size (your 640mg num)
INPUT= #the input drive device file, probably an arg
OUTPUT= #the output file, probably an arg
while [ $WRITTEN -lt $FILESIZE ]
do
dd if=$INPUT of=$OUTPUT seek=$WRITTEN bs=1 count=$INC
#i'm ignoring error handling here, you should not
WRITTEN=(($INC + $WRITTEN))
#i'm guessing you're wanting to change $OUTPUT here?
done
That's not everything you need, but it's enough of a skeleton to get you started.
HTH,
Kevin
More information about the Discuss
mailing list