TransWikia.com

dd script with timings

Unix & Linux Asked by lmind on December 22, 2021

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?

One Answer

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

Answered by lmind on December 22, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP