スクリプトの実行中にカウントを増やすスクリプトが必要です。デフォルトでは、同じ国で10台のデバイスがダウンしていることがわかったら、電子メール通知を送信し、各ダウンタイム後にスクリプトを実行したいと思います。
したがって、カウンタを0に設定すると、スクリプトは値を1に更新しますが、次回スクリプトが実行されるとカウンタが0に設定されていることを確認し、値を1に戻します。
国名に関連付けられた以前のカウンタ値は両方の値が固定されていないため、保存する必要があります。さまざまな国n
に属するデバイスもたくさんあります。n
ベストアンサー1
国ごとに1つのファイル/カウンタ。
#!/bin/bash
#Country name is specified as a comamnd line argument
# ie device_count.sh Brazil
if [[ -z "$1" ]] ; then
echo "Please specify country name" >&2
exit 1
fi
#Create a new file per country if one doesn't exist already
COUNTER_FILE=/var/tmp/devices.$1
if [[ -r $COUNTER_FILE ]] ; then
COUNT=$(<$COUNTER_FILE)
else
COUNT=0
fi
#Increment counter and save to file
echo $(( $COUNT += 1 )) > $COUNTER_FILE
#check if we need to send email
if [[ $(( $COUNT % 10 )) -eq 0 ]] ; then
#We have reached 10 - we need to send an email
echo "BLAH BLAH BLAH " | mailx -s "reached 10" [email protected]
fi