Some changes on report_accounts.sh

* s/cat|grep|awk/awk/
* Speak english
* Use mktemp
This commit is contained in:
Florent 2012-04-30 15:27:24 +02:00
commit c7295c6711

View file

@ -5,48 +5,43 @@
# (Compatible Debian Squeze) # (Compatible Debian Squeze)
# Public domain <BohwaZ> # Public domain <BohwaZ>
SUBJECT="[Banques] Rapport des comptes" SUBJECT="[Bank] Accounts report"
TMPSTORAGE="/tmp/" TMPSTORAGE=`mktemp -d`
rm -f ${TMPSTORAGE}account* boobank -q -f table list > ${TMPSTORAGE}/account_list
boobank -q -f table list > ${TMPSTORAGE}account_list ACCOUNTS=`awk '/@/ {print $2}' ${TMPSTORAGE}/account_list`
ACCOUNTS=`cat ${TMPSTORAGE}account_list | fgrep '@' | awk '{print $2}'`
for i in $ACCOUNTS for i in $ACCOUNTS
do do
boobank -q -f table history "$i" > ${TMPSTORAGE}account_history_${i} boobank -q -f table history "$i" > ${TMPSTORAGE}/account_history_${i}
boobank -q -f table coming "$i" > ${TMPSTORAGE}account_coming_${i} boobank -q -f table coming "$i" > ${TMPSTORAGE}/account_coming_${i}
done done
echo "Ceci est le rapport des comptes bancaires, généré automatiquement." > ${TMPSTORAGE}account_mail echo "Bank accounts report, generated by boobank\n" > ${TMPSTORAGE}/account_mail
echo >> ${TMPSTORAGE}account_mail cat ${TMPSTORAGE}/account_list >> ${TMPSTORAGE}/account_mail
cat ${TMPSTORAGE}account_list >> ${TMPSTORAGE}account_mail echo >> ${TMPSTORAGE}/account_mail
echo >> ${TMPSTORAGE}account_mail
for i in $ACCOUNTS for i in $ACCOUNTS
do do
echo "Dernières opérations sur le compte $i" >> ${TMPSTORAGE}account_mail echo "Last operations for account $i \n" >> ${TMPSTORAGE}/account_mail
echo >> ${TMPSTORAGE}account_mail cat ${TMPSTORAGE}/account_history_${i} >> ${TMPSTORAGE}/account_mail
cat ${TMPSTORAGE}account_history_${i} >> ${TMPSTORAGE}account_mail echo >> ${TMPSTORAGE}/account_mail
echo >> ${TMPSTORAGE}account_mail if [ -s ${TMPSTORAGE}/account_coming_${i} ]
if [ -s ${TMPSTORAGE}account_coming_${i} ]
then then
echo "Opérations à venir sur le compte $i" >> ${TMPSTORAGE}account_mail echo "Coming operations for account $i \n" >> ${TMPSTORAGE}/account_mail
echo >> ${TMPSTORAGE}account_mail cat ${TMPSTORAGE}/account_coming_${i} >> ${TMPSTORAGE}/account_mail
cat ${TMPSTORAGE}account_coming_${i} >> ${TMPSTORAGE}account_mail echo >> ${TMPSTORAGE}/account_mail
else else
echo "Pas d'opération à venir sur le compte $i" >> ${TMPSTORAGE}account_mail echo "No coming operation for $i \n" >> ${TMPSTORAGE}/account_mail
fi fi
echo >> ${TMPSTORAGE}account_mail
done done
if [ "$1" = "--mail" ] if [ "$1" = "--mail" ]
then then
cat ${TMPSTORAGE}account_mail | mail -s "$SUBJECT" -a "Content-type: text/plain; charset=UTF-8" "$2" cat ${TMPSTORAGE}/account_mail | mail -s "$SUBJECT" -a "Content-type: text/plain; charset=UTF-8" "$2"
else else
cat ${TMPSTORAGE}account_mail cat ${TMPSTORAGE}/account_mail
fi fi
rm -f ${TMPSTORAGE}account* rm -rf ${TMPSTORAGE}