#check_mail
#
#    Shell script to check if user has mail. To be run automatically by
#    cron every ten minutes. Add the following file into root crontab :-
#
#    1,11,21,31,41,51 * * * * /bin/ksh /check-mail > /dev/null
#
#    John Roebuck  -  25/07/97.
#

temp_fname1=/tmp/$$_mailcheck1

ls -l /var/spool/mail/ |awk '{ print $3  "  " $5 }' > $temp_fname1

{
while read mail_data
do
        mail_user=`echo $mail_data |awk '{print $1}'`
        mail_value=`echo $mail_data |awk '{print $2}'`
        mail_who=`who |grep $mail_user`
	mail_tty=`echo $mail_who |cut -d" " -f2`
	Terminal=/dev/$mail_tty

        if [ "$mail_tty" != "" ]
        then    

            if [ "$mail_value" != "0" ]
            then
                 mail_wall=" **> "$mail_user" You have mail !!! <** "
	         print  $mail_wall  > $Terminal
            fi
        fi

done } < $temp_fname1
rm $temp_fname1 > /dev/null 2>&1
