Wise Monks,

I was asked to put together a script that will write hex to a block device until it is full using a variable for the block size. I think that I have accomplished this with the script below, with help from the chatterbox (thanks everyone).

#!/usr/bin/perl die "Usage: hexperlscript <blocksize> <destination file>\n" unless @AR +GV == 2; ($input, $output) = @ARGV; if ($input % 512 == 0) { $input = $input * .5; open ( DEST, '>>', $output ) or die "Cannot create ouput file. $! \n"; while (1 < 2) { for(0..0xff){$n=sprintf"%02x",$_;print DEST "$n" x $input;} print DEST "$n" x $input; } } else { print "Blocksize must be divisable by 512.\nExiting.\n"; END; }
My problem now is, how can I terminate the script? I was hoping that when the block device was full, it would just error out, and then I could work it from there, but it doesn't. When this is run against /dev/hdaX it works, but does not terminate. Is there a way in which I can write to the device until it is full and then end the script?

A little background: I have some forensics guys that I work with that want to use this in order to test where data is written between two or more drives on a SCSI device. This is really the first script that I have ever put together that does something useful so (as always) all comments are welcome.

Thank you,
ghettofinger


In reply to Block device status and script termination by ghettofinger

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.