Script not running from cron it gives blank output

Hi,

I have ascript which drops a mail with the jobs status.

here is the script:

#!/bin/ksh
mypath=/home/gaddamja
flashlogpath=/sbcimp/dyn/data/flash/log
cd $mypath
 
v1=`ls -lrt | grep -i checkFilesForAmber_EUR1. |tail -1 | awk '{print $8}'`
v2=`cat $v1`
 
cd $flashlogpath
 
v3=`grep "/home/flash/flash/batch/bin/runAmberLight.ksh finishes at:" runAmberLight.log | head -1 | cut -d" " -f4-9`
v6=`grep "/home/flash/flash/batch/bin/setLights.ksh end at" setLights.log | head -1 | cut -d" " -f4-9`
 
/sbcimp/run/tp/CA/Autosys/v4.0/bin/autorep -j FI_flashprd_Amber_Asia_Box >$mypath/fileAsia.txt
v11=`cat $mypath/fileAsia.txt`
 
/bin/echo "Hi ,Please find the detailed Flash Batch Report for $v2 \n\n(1) Asia Light Setting:\n\n.The amber lights were set at $v3 and turned to green at $v6\n\n ---$v11\n---\n\n" >$mypath/mail_temp
 
cat $mypath/mail_temp | mailx" -s "Flash Batch Report for COB $v2" abc@abc.com
exit 0
 

This script work fine from me if i run it manually.Its giving blank values for the highlighted line when i run from the cron.

the 'fileasia' file contains the following error rather than the status of the 'job FI_flashprd_Amber_Asia_Box '

here is the error goes:

The environmental variable AUTOSYS is not set !
Oracle Logon Error: ORA-12545 and ORA-12545
Oracle Logon Error: Unable to display error message for ORA-12545 and ORA--12545
Please check the Oracle Messages manual
Unable to get encoded and plaintext passwords for

I wanted to know why its giving the error when i run from Cron and why its running fine if i run normally

Can some one pls help...

Many thanks in advance !!

The environment in cron isn't the same as your interactive environment. The error tells you as much: the variable AUTOSYS is not set (and probably others.) You will have to import the required environment variables into the script you run from cron.

You can do "printenv" from your interactive ksh session and from a cron script to compare the environment.