0

私は bash に精通しているわけではありませんが、いくつかのコマンドを知っており、ある程度は回避できます。Ubuntu (組み込み Linux) を実行している外部デバイスのフラッシュ ドライブをいっぱいにするスクリプトを書くのに問題があります。

dd if=/dev/urandom of=/storage/testfile.txt

フラッシュ ドライブがいっぱいになったとき (ランダム データの書き込みを停止したとき) を知りたいので、他の操作を続行できます。

Python では、次のようにします。

while ...condition:

    if ....condition:
        print "Writing data to NAND flash failed ...."
        break
else:
    continue

しかし、bashでこれを行う方法がわかりません。ご協力いただきありがとうございます。

4

2 に答える 2

1

ごとにman dd

DIAGNOSTICS
     The dd utility exits 0 on success, and >0 if an error occurs.

これがスクリプトで行うべきことです。dd コマンドの後の戻り値を確認するだけです。

dd if=/dev/urandom of=/storage/testfile.txt
ret=$?
if [ $ret gt 0 ]; then
    echo "Writing data to NAND flash failed ...."
fi
于 2013-04-23T18:08:51.850 に答える
0

これを試して

#!/bin/bash

filler="$1"     #save the filename
path="$filler"

#find an existing path component
while [ ! -e "$path" ]
do
    path=$(dirname "$path")
done

#stop if the file points to any symlink (e.g. don't fill your main HDD)
if [ -L "$path" ]
then
    echo "Your output file ($path) is an symlink - exiting..."
    exit 1
fi

# use "portable" (df -P)  - to get all informations about the device
read s512 used avail capa mounted <<< $(df -P "$path" | awk '{if(NR==2){ print $2, $3, $4, $5, $6}}')

#fill the all available space
dd if=/dev/urandom of="$filler" bs=512 count=$avail 2>/dev/null
case "$?" in
    0) echo "The storage mounted to $mounted is full now" ;;
    *) echo "dd errror" ;;
esac
ls -l "$filler"
df -P "$mounted"

コードをファイルに保存します。たとえば、次ddd.shのように使用します。

bash ddd.sh /path/to/the/filler/filename

コードはhttps://stackoverflow.com/users/171318/hek2mglの助けを借りて行われます

于 2013-04-23T23:03:52.163 に答える