#!/bin/sh export TZ=CET FREEALLOWANCE=300 FINCHECK='/usr/local/bin/fincheck' FILLERL=" " FILLERM=" " FILLERS=" " echopad() { # string filler LEN=${#1} echo -n "$1$2" | sed -e "s/.\{${#1}\}$//" } getfreecountries() { # service lynx -dump http://www.$1/en/rates.html \ | sed -n "s/[[:space:]]*\([^)]\+[)]\).*[Ff][Rr][Ee][Ee][*].*[Ff][Rr][Ee][Ee][*].*/ \1/p" } mailuser() { case _"$REMAININGDAYS" in _) return ;; esac case _"$USEDMINUTES7" in _) return ;; esac case _"$EMAIL" in _) return ;; esac sleep 1 YESTERDAYUSEDMINUTES7=$($FINCHECK last7daysminutes $SERVICE $USR $PWD 1) case _"$YESTERDAYUSEDMINUTES7" in _) return ;; esac TODAYAVAIL=$(($FREEALLOWANCE - $USEDMINUTES7)) YESTERDAYAVAIL=$(($FREEALLOWANCE - $YESTERDAYUSEDMINUTES7)) FREELIST=$(getfreecountries $SERVICE) case _"$FREELIST" in _) return ;; esac cat<<-ENDMAIL | mail -s \ "Your $SERVICE account: credit=$CREDITCENTS Ec; free=$TODAYAVAIL min; expiry in $REMAININGDAYS days"\ $EMAIL Good morning, $USR. Here's the status of your $SERVICE account: - For paid destinations, your credit is $CREDITCENTS eurocents (expiring in $REMAININGDAYS days from today unless the account is topped up before that date). - For free destinations, you have $TODAYAVAIL minutes (you ended yesterday with $YESTERDAYAVAIL minutes of your allowance unused). As you know, you can place calls for up to $FREEALLOWANCE minutes over the last 7 days to a list of free destinations, after which calls to those destinations get charged at the rate of 1 eurocent (about HKD 0.10) per minute. For $SERVICE, the current free destinations list is: $FREELIST For the complete list of the per-minute rates (in eurocents) for calls to other destinations, see: http://www.$SERVICE/en/rates.html Happy $SERVICE calling! --- This free daily notification service is offered to you by $USERNAME@$(hostname). ENDMAIL } echo "Report at $(TZ=UTC-8 date) ($(date))" echopad User "$FILLERL" echopad Service "$FILLERL" echopad DaysLeft "$FILLERM" echopad 7days "$FILLERS" echopad month "$FILLERS" echopad l.mth "$FILLERS" echo "Credits (Ec)" echopad ============= "$FILLERL" echopad ============= "$FILLERL" echopad ======== "$FILLERM" echopad ===== "$FILLERS" echopad ===== "$FILLERS" echopad ===== "$FILLERS" echo "============" (cat <<-EOF voipstunt.com vsuser pspassword vsu@example1.com sipdiscount.com sduser sdpassword sdu@example2.com voipdiscount.com vduser vdpassword vdu@example3.com EOF ) | while read SERVICE USR PWD EMAIL; do case _"$SERVICE" in _#*|_\;*) continue; ;; esac echopad "$USR" "$FILLERL" echopad "${SERVICE%.*}" "$FILLERL" # remaining days sleep 1 REMAININGDAYS=$($FINCHECK remainingdays $SERVICE $USR $PWD) case _"$REMAININGDAYS" in _) echopad "- " "$FILLERM" ;; *) echopad "$REMAININGDAYS" "$FILLERM" ;; esac # last 7 days: sleep 1 USEDMINUTES7=$($FINCHECK last7daysminutes $SERVICE $USR $PWD) case _"$USEDMINUTES7" in _) echo "*** NOT FOUND ***" continue ;; *) echopad "$USEDMINUTES7" "$FILLERS" ;; esac # last month: # this month: sleep 1 USEDMINUTES=$($FINCHECK usedminutes $SERVICE $USR $PWD) case _"$USEDMINUTES" in _) echo "*** NOT FOUND ***" continue ;; *) echopad "$USEDMINUTES" "$FILLERS" ;; esac # last month: sleep 1 USEDMINUTES=$($FINCHECK usedminutes $SERVICE $USR $PWD 1) case _"$USEDMINUTES" in _) echo "*** NOT FOUND ***" continue ;; *) echopad "$USEDMINUTES" "$FILLERS" ;; esac sleep 1 CREDITCENTS=$($FINCHECK creditcents $SERVICE $USR $PWD) case _"$CREDITCENTS" in _) echo "*** NOT FOUND ***" continue ;; *) echo -n "$CREDITCENTS" ;; esac echo mailuser done