Script Contain Send Mail via Telnet

Dear Masters,

I am using Solaris 10 and bash shell. I make a script for checking if a file is exists on the specified folder or not from 5th day of the month until the end of the month. If the file doesn't exist, the script will send email to me. The script ran perfectly when I execute it on foreground. But when I put it on crontab, it doesn't send me email when the script is finished.

Below is the script for checking file:

#!/bin/sh
day=`date +%d`
month=`date +%m`
lmonth=`expr $month - 1`
if test "$lmonth" = "0"
        then
        lmonth=12
        year=`expr $year - 1`
fi
year=`date +%Y`
hour=`date +%H`
sales=_SALES.csv
filename=$year$lmonth$sales
text="This file is not found on the server:"
sales_dir=/sales/
did=`cat /test-script/var`

if day=05 && hour=8
        then
                did=0
                echo "$did" > /test-script/var
fi

if did=0
        then
                cd $sales_dir
                if [ -f $filename ]
                        then
                        did=1
                        echo "$did" > /test-script/var
                        echo "File found - $date" >> /test-script/sales.log
                else
                        echo "$text" > /test-script/mail/mail.txt
                        echo "$filename" >> /test-script/mail/mail.txt
                        /test-script/sendmail.sh |telnet > /test-script/mail/mail.log
                fi
        else
                exit 0
        fi

The script will send mail via telnet. Below is the script for sending mail:

#!/bin/sh
host=10.14.1.105
port=25
echo open $host $port
sleep 1
echo helo $host
sleep 1
echo mail from:salesreport@company.com
sleep 1
echo rcpt to:kris.@company.com
sleep 1
echo data
sleep 1
echo to:kris.@company.com
sleep 1
echo subject:SALES REPORT File Not Found!
sleep 1
echo ""
sleep 1
echo ""
sleep 1
cat /test-script/mail/mail.txt
sleep 1
echo .
sleep 1
echo quit
#end

Need your help to guide me on this case.
Thanks in advance.
Kris

When script runs in interactive mode but not in batch ( cron) you can almost be sure it has something to do with your environment: You have in it set something cron ignores and needs... then when you execute it who/where are you, and when its cron?...

Hi vbe,

Thanks for your answer.
Either foreground/interactive mode or in cron, the script run on the same user.

but where are you when you run the script? Do you have nothing in your logs? and cron logs?

I would say it may be because of telnet...

Try to get the return code from the telnet command, is it 1?

hi it looks like there is some problem with

 /test-script/sendmail.sh 

script can u run entire script in debug mode