1

Trying to figure out the best approach to a script that will do the following:

  1. Create a loop script that creates a 10GB file using dd where, upon completion, removes the file, then repeats 25 times or if CTRL+C is typed before the script gets the chance to exit.
  2. At the end of each operation, i.e. dd, then rm, time it so we know exactly how long dd and rm took

So far, I'm thinking something along these lines:

for i in {1..25}
  do
    time sh -c "dd if=/dev/zero of=/user/home/test.img bs=10G count=1" >> /tmp/dd_timed.txt && time sh -c "rm -f /user/home/test.img" >> rm_timed.txt
done

Anyone have a better solution or could maybe tweak this a bit?

  • Do not set bs=10G count=1; it will uselessly eat up a lot of RAM that way. Set bs=1G count=10. Or set bs=16M count=10G iflag=count_bytes for greater flexibility. – DepressedDaniel Dec 15 '16 at 21:35
  • Ok. Understood - thanks for the suggestion. One of the problems is that it doesn't appear dd or rm are writing to /tmp within the files specified. They're literally zero bytes. I saw on another forum how, instead of using a single > redirect, one had to use 2> because of something funky that time was doing, but I'm trying to append because I need to know how long each iteration of dd and rm are taking. – lmind Dec 15 '16 at 21:47
  • Yeah, you'll probably have to do 2>>/tmp/whatever as time prints statistics to standard error. In fact, if you're using bash, you'll even have to put time in a subshell: ( time ... ) 2>>/tmp/.... Or use the real /usr/bin/time ... 2>//tmp/.... – DepressedDaniel Dec 15 '16 at 22:12
0

Ok, so it looks like here's the way to get this done. Looks nasty, but works:

#!/bin/bash
for i in {1..25}
do
{ time dd if=/dev/zero of=/home/user/test.img bs=1G count=10 oflag=direct >& / dev/null ; } 2>> /tmp/dd_timed.txt && { time rm /home/user/test.img >& /dev/null ;  } 2>> /tmp/rm_timed.txt
done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.