あなたが直接これはbashでfor-loop
を研究するベンチャーであるならば、あなたは
以下のように同じことを行うことができ、以下のように
df
に、配列を供給し、しかし
for-loop
よう
df -H "${array[@]}"
の使用を避けることができます
for i in "${array[@]}"
do
df -H "$i"
# Well, "${array[@]}" expands to everything in array
# and i takes each value in each turn.
done
そして、あなたは、インデックスを使って配列にアクセスしたい場合は、
for ((i = 0; i < ${#array[@]}; i++)) # This is a c-style for loop
do
df -H "${array[i]}" # Note the index i is not prefixed with $
done
編集
使用量はたとえば、10ギガバイト
# We will usage file which we would use to fill the body of mail
# This file will contain the file system usage
# But first make sure the file is empty before every run
cat /dev/null > /tmp/diskusagereport
for i in "${array[@]}"
do
usage=$(df -H "$i" | awk 'END{sub(/G$/,"",$3);print $3}')
if [ "${usage:-0}" -gt 10 ]
then
echo "Filesystem : ${i} usage : ${usage}GB is greater than 10GB" >> /tmp/diskusagereport
fi
done
#finally use the `mailx` client like below
mailx -v -r "[email protected]" -s "Disk usage report" \
-S smtp="smtp.yourserver.org:port" -S smtp-auth=login \
-S smtp-auth-user="your_auth_user_here" \
-S smtp-auth-password='your_auth_password' \
[email protected] </tmp/diskusagereport
が同様に '((I = 0のために運動を締めくくりかもしれないが、より多くのであるかどうかを確認するには、 i <$ {#array [@]}; i ++)); df -H "$ {array [i]}";を実行します。 done' ... ':)' –
しかし、dfの結果はどのように変数になりましたか?考え方は、結果を変数に保存して、実行できるようにすることです。 – Ceac
@Cacこの変数で何をやっているのか分かりますか?しばしば、それに基づいて計算を行うために 'df'から特定の値が必要になります。 – sjsam