3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

メモ:ddコマンドで書き込みテスト

Posted at

ちょっとしたパフォーマンステストで、書き込みを延々とし続けてほしいことがあった。

でも、Diskは溢れさせたくない。そんなときのスクリプト。

dd_write_loop.sh
# !/bin/bash

LOOP_COUNTS=100
OUTPUT_FILE_DIR="/tmp"
OUTPUT_FILE_NAME_PREFIX="dd_test"
BLOCK_SIZE="10M"
BLOCK_COUNT=100

trap "/bin/rm ${OUTPUT_FILE_DIR}/${OUTPUT_FILE_NAME_PREFIX}.*; exit" SIGINT

for ((i=0; i<$LOOP_COUNTS; i++))
do
  output_file="${OUTPUT_FILE_DIR}/${OUTPUT_FILE_NAME_PREFIX}.${i}"

  # 書き込み実行
  # "oflag=direct"はメモリを通さずDiskに直接書き込む(Direct I/O))
  /bin/dd if=/dev/zero of=${output_file} bs=${BLOCK_SIZE} count=${BLOCK_COUNT} oflag=direct
  # 一時ファイル削除
  /bin/rm ${output_file} && echo "ファイル削除完了: ${output_file}"
done

とめたくなったらCtrl + Cする。SIGINTをtrapしてあるので、ゴミファイルは残らない。

出力がうっとうしければ/dev/nullに捨てる。そして適当にバックグラウンドで動かしたりするとよい。

./dd_wirte_loop >/dev/null 2>&1 &

とめたくなったら、fgコマンドを実行した上で、Ctrl + Cをする。

メモ

ddのオプションはifofiflagoflagなどクセがあって覚えにくい。と思ったら、INPUT、OUTPUTの頭文字だと気づいた。(今更)

ifはインプットファイル、iflagはインプットフラグ。(たぶん)

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?