4

I'm trying to test an embedded nand flash chip using the dd command (write random data to a file):

dd if=/dev/urandom of=/nand/storage/testnand/test.raw bs=100000 count=50 2> /dev/null

However, the unit I'm testing is running busybox v1, and it has been patched. The dd command is not recognized. Is there an alternative command that will help me achieve the same results?

suffa
  • 815
  • 1
  • 7
  • 10

2 Answers2

4

You can try

  • cat /dev/urandom > /nand/storage/testnand/test.raw
  • for i in $(seq 1 10000000); do echo $i >> /nand/storage/testnand/test.raw; done

I can't think of much else that would work if you don't even have dd or cat...

allquixotic
  • 34,215
  • 7
  • 113
  • 145
  • Expanding on your idea, I'd do `{ for i in {1..100000}; do echo $i; done } > test.raw` which opens test.raw only 1 time – ignis May 03 '13 at 18:29
  • @ignis does the ellipsis in your comment account for: {1 seq 10000000}? – suffa May 03 '13 at 18:34
  • @suffa Nope, it's an alternative syntax for `seq 1 100000`, documented [here](http://mywiki.wooledge.org/BashGuide/TestsAndConditionals#Conditional_Loops_.28while.2C_until_and_for.29) and [here](http://www.gnu.org/software/bash/manual/bashref.html#Brace-Expansion) – ignis May 03 '13 at 18:37
3
head -c $((100000*50)) /dev/urandom > test.raw

will save 100000 * 50 = 5000000 bytes, combining Bash's Arithmetic expressions and head's -c number_of_bytes parameter.

For debugging: expanding on allquixotic's idea, this command prints "$i done" at 1000, 2000, etc.

{ for i in {1..100000}; do echo $i; if (( ($i % 1000) == 0 )); then echo "$i done" 1>&2; fi; done } > test.raw
ignis
  • 262
  • 1
  • 8
  • Ooh nice! :) Didn't think of generating data with `head`... – allquixotic May 03 '13 at 18:19
  • @ignis - If I wanted this script to continue until there is an error or the user stops, would I need to add /dev/null back? – suffa May 03 '13 at 18:30
  • @suffa The user can stop with Ctrl+C, and I believe the command will stop automatically if there's an error. `2>/dev/null` merely hides the error messages, in no way it will influence the command itself. – ignis May 03 '13 at 18:34
  • @ignis - keep getting a syntax error on the debugging section you added recently. – suffa May 03 '13 at 19:18
  • @suffa I do not get errors, on Bash 4.2.37(1) / Ubuntu 12.10, Bash 4.2.45(2) / Arch Linux 2013.04, Bash 4.2.39(1) / Fedora 18. Does `echo $0` return "bash"? If so, what version does `bash --version` print? – ignis May 03 '13 at 19:39
  • @ignis - I will make sure I didn't make any typos. ... on BusyBox v1.10.2-uc0 ... built-in shell (msh) – suffa May 03 '13 at 19:44
  • @suffa Please try `for i in $(seq 1 100000); do echo $i; if (( ($i % 1000) == 0 )); then echo "$i done" 1>&2; fi; done > test.raw` but I won't be able to help if it does not work, because different shells have slightly different syntaxes, and because I do not know msh. The links I gave in the comments are for Bash. Please retag the question as msh, to increase the probability that someone that knows that shell bumps into the question. – ignis May 03 '13 at 19:51