#!/bin/ksh
# A daily reminder of how long you need to carry on toiling ...
# Substitute or export the $INSTANCE, $DATABASE and retirement date of your choice. 
# Non-AIX environments may not support all terminfo variables.
# Alex Levy

function boxit {
# An ancient piece of code written in 1997 by an unknown author.
# This function displays its argument to stdout inside a highlighted box.
clear #optional, the clear command will clear the screen and so place output at the top of the new screen.

cud=$(tput cud1) ; cud=$(echo "\033[B\c")
cuu=$(tput cuu1)  
cur=$(tput cuf1)
sbox=$(tput smso)$(tput smcup)$(tput font1)
ebox=$(tput rmcup)$(tput font0)
tidy=$(tput rmso)
boxset=$(tput box2)
for char in 1 2 3 4 5 6 
do
	eval b$char=$(print $boxset | cut -c$char,$char)
done
	
function repeat
{
typeset char=$1
typeset -i i=0 length=$2
print "$(while(((i=i+1)<=$length));do print "$char\c";done)\c"
}
	
typeset -i right=0 down=0 length char
typeset message=$@ line cdwn crht cend
((length=${#message}+4))

line=$(repeat $b2 $length)
cdwn=$(repeat $cud $down)
crht=$(repeat $cur $right)
cend=$(repeat $cur $length)
        
print "$crht$sbox$b1$line$b3$ebox"
print "$crht$sbox$b4$ebox  $message  $sbox$b4$ebox"
print "$crht$sbox$b6$line$b5$ebox"

print "$cuu$cuu$crht$cend$tidy\n\n"

}

. /home/$INSTANCE/sqllib/db2profile
db2 "connect to $DBALIAS" 1> /dev/null

db2 -x "values('You have ',smallint(days('2017-08-29') - days(current date)), \
       ' days to go until ','you can collect ','your pension. ')"  > /tmp/pension

db2 connect reset 1> /dev/null
boxit `cat /tmp/pension` && rm -f /tmp/pension 2> /dev/null
