レポートとブロック サイズを比較し続けることができます。はい、デバイスを一度だけ開いて、読み続ける必要があります。
TAPE=/dev/nst0
BLOCK_SIZE=32768
COUNTER=1
while [ "$(dd bs="$BLOCK_SIZE" of="file_$COUNTER" 2>&1 count=1 | awk '/bytes/ { print $1 }')" -eq "$BLOCK_SIZE" ]; do
let ++COUNTER
done < "$TAPE"
スクリプトはファイルでテストされます。
最後に読み取ったバイト数が 0 の場合は、最後のファイルを削除することもできます。
while
BYTES_READ=$(dd bs="$BLOCK_SIZE" of="file_$COUNTER" 2>&1 count=1 | awk '/bytes/ { print $1 }')
[ "$BYTES_READ" -eq "$BLOCK_SIZE" ]
do
let ++COUNTER
done < "$TAPE"
[ "$BYTES_READ" -eq 0 ] && rm -f "file_$COUNTER"
テープの処理中にメッセージを送信したい場合は、リダイレクトを使用して別のファイル記述子を使用できます。
TAPE=temp
BLOCK_SIZE=32768
COUNTER=1
while
FILE="file_$COUNTER"
echo "Reading $BLOCK_SIZE from $TAPE and writing it to file $FILE."
BYTES_READ=$(dd bs="$BLOCK_SIZE" of="$FILE" count=1 2>&1 <&4 | awk '/bytes/ { print $1 }')
echo "$BYTES_READ bytes read."
[ "$BYTES_READ" -eq "$BLOCK_SIZE" ]
do
let ++COUNTER
done 4< "$TAPE"
[ "$BYTES_READ" -eq 0 ] && rm -f "$FILE"
出力例:
Reading 32768 from temp and writing it to file file_1.
32768 bytes read.
Reading 32768 from temp and writing it to file file_2.
32768 bytes read.
Reading 32768 from temp and writing it to file file_3.
32768 bytes read.
Reading 32768 from temp and writing it to file file_4.
32768 bytes read.
Reading 32768 from temp and writing it to file file_5.
32268 bytes read.
もう 1 つのオプションは、 を に送信するecho
こと/dev/stderr
です。
echo "Reading $BLOCK_SIZE from $TAPE and writing it to file $FILE." >&2
また、少し高速化するexec
には、サブシェル内で使用して余分なフォークを防ぎます。
BYTES_READ=$(exec dd ...)