Skip to content
report_accounts.sh 1.54 KiB
Newer Older
#!/bin/sh
BohwaZ's avatar
BohwaZ committed
# Rapport des comptes bancaires
# Liste l'intégralité des comptes dans Boobank, leurs dernières opérations et les opérations à venir
# et envoie ça par mail si --mail machin@example.tld est spécifié, sinon ça affiche
# (Compatible Debian Squeze)
# Public domain <BohwaZ>

SUBJECT="[Bank] Accounts report"
TMPSTORAGE=`mktemp -d`
BohwaZ's avatar
BohwaZ committed

boobank -q -f table list > ${TMPSTORAGE}/account_list
BohwaZ's avatar
BohwaZ committed

ACCOUNTS=`awk '/@/ {print $2}' ${TMPSTORAGE}/account_list`
BohwaZ's avatar
BohwaZ committed

for i in $ACCOUNTS
do
	boobank -q -f table history "$i" > ${TMPSTORAGE}/account_history_${i}
	boobank -q -f table coming "$i"  > ${TMPSTORAGE}/account_coming_${i}
BohwaZ's avatar
BohwaZ committed
done

printf "Bank accounts report, generated by boobank\n" > ${TMPSTORAGE}/account_mail
cat ${TMPSTORAGE}/account_list >> ${TMPSTORAGE}/account_mail
printf "\n" >> ${TMPSTORAGE}/account_mail
BohwaZ's avatar
BohwaZ committed

for i in $ACCOUNTS
do
	printf "Last operations for account $i \n" >> ${TMPSTORAGE}/account_mail
	cat ${TMPSTORAGE}/account_history_${i} >> ${TMPSTORAGE}/account_mail
	printf "\n" >> ${TMPSTORAGE}/account_mail
	if [ -s ${TMPSTORAGE}/account_coming_${i} ]
BohwaZ's avatar
BohwaZ committed
	then
		printf "Coming operations for account $i \n" >> ${TMPSTORAGE}/account_mail
		cat ${TMPSTORAGE}/account_coming_${i} >> ${TMPSTORAGE}/account_mail
                printf "\n" >> ${TMPSTORAGE}/account_mail
BohwaZ's avatar
BohwaZ committed
	else
		printf "No coming operation for $i \n" >> ${TMPSTORAGE}/account_mail
BohwaZ's avatar
BohwaZ committed
	fi
done

if [ "$1" = "--mail" ]
then
        cat ${TMPSTORAGE}/account_mail | mail -s "$SUBJECT" -a "Content-type: text/plain; charset=UTF-8" "$2"
BohwaZ's avatar
BohwaZ committed
else
        cat ${TMPSTORAGE}/account_mail
rm -rf ${TMPSTORAGE}