Um arquivo / contador por país.
#!/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