[NTLUG:Discuss] Output to Multiple Files - Now More

Fred James fredjame at fredjame.cnc.net
Thu Apr 7 14:30:55 CDT 2005


Patrick R. Michaud wrote:

>On Thu, Apr 07, 2005 at 11:34:43AM -0500, Fred James wrote:
>  
>
>>David Wilson wrote:
>>
>>    
>>
>>>My goal is to capture a forensic image of a hard drive
>>>to a dd type of file. I need to split it into chunks
>>>(FAT32 limitation).  My process requires that I have
>>>two copies of the files when complete.  I am trying to
>>>save the time required to make a copy.  
>>>      
>>>
>
>  
>
>>So maybe ...
>>dd if=/dev/sdb | split -b 640m
>>for i in `ls x??`
>>do
>>   cat $i | tee /path_1/$i /path_2/$i_2 2>&1 /dev/null
>>done
>>    
>>
>
>I think David's purpose is to avoid the expense of reading
>the image "twice" -- i.e., to be able to read it once and
>write it to two places simultaneously.  Almost anything
>involving split/cat means that everything is being read
>twice.  Otherwise we could just do
>
>   split -b 640m /dev/sdb
>   cp x?? /path_1
>
>which is basically the equivalent of the above but
>requires that the contents are read twice.
>
>I don't think split/tee (or the shell) are going to get David 
>where he wants to go -- this might be a case where it's better to do 
>things with a Perl script or a specialized C program designed
>for the purpose.  
>
>Pm
>  
>
Patrick R. Michaud
Yes, of course you are right.  With split you have one read (and write 
to multiple files), and then tee adds another read (with simultaneous 
writes to n files).

The original requirement was to write to two destinations from one 
read.  Then the requirement to break the file into smaller pieces first 
was added.  The first requirement is satisfied with tee, and the second 
by adding split and the for loop.  Granting that there is a read/write 
sequence for each (the split and the tee), there is still not an extra 
write to copy the file(s) to the second destination (just the need to 
have the space locally to temporarily write all the files resulting from 
split).

I suppose a probable answer might be to employ pipes (i.e., define 2 
pipes, each writing to the desired destination).  But whether C, Perl, 
Bourne, or Bash, tee may well still be the most efficient way to write 
to multiple destinations from one read.  Of course I could be wrong there.
Regards
Fred James

-- 
Compassion alone stands apart from the continuous traffic between good and evil proceeding within us.  "Om Mani Padme Hum"





More information about the Discuss mailing list