[NTLUG:Discuss] Bash Shell Script

Wilson, David David.Wilson at FTIConsulting.com
Wed Aug 20 13:30:46 CDT 2003


Thanks!

-----Original Message-----
From: kbrannen at gte.net [mailto:kbrannen at gte.net]
Sent: Tuesday, August 19, 2003 10:08 PM
To: NTLUG Discussion List
Subject: Re: [NTLUG:Discuss] Bash Shell Script


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


_______________________________________________
https://ntlug.org/mailman/listinfo/discuss



More information about the Discuss mailing list