strange CRON problem

Hi All,

I am facing a strange problem with my shell script when I run the script from CRON.

script----

#!/bin/ksh
date_var=`date "+%Y%m%d%H%M%S"`
memory_file_name=Mem-"$date_var".csv

total_memory_mb=`prtconf -v | grep Memory |tr -s " " "," | cut -f3 -d ','`
total_memory_kb=`expr $total_memory_mb \* 1024`
echo total memory is $total_memory_kb >> script-"$date_var".log
free_memory=`vmstat 1 1 |grep -v memory |grep -v swap|tr -s " " "," |cut -f6 -d ','`
used_memory=`expr $total_memory_kb - $free_memory`
echo calaculated memory informations >>script-"$date_var".log
#write memory details to file
echo Used,Free,Total,Date >> $memory_file_name

echo $used_memory,$free_memory,$total_memory_kb,$date_var >> $memory_file_name
echo Finished writing to file >>script-"$date_var".log

when I run the script after logging into server it works fine...but when I run the script using CRON it doesn't give me output for total_memory_kb and used_memory ..

I couldn't understand why its happening...

any suggestions please....

paste the cron entry .....

CRON entry.....

15 * * * * /domain/appplication/memory/script.sh >> /domain/appplication/memory/log/cron.log

try using absolute pathnames in your script.

can you please explain what you mean by "absolute pathnames in your script"

I have the script in /domain/appplication/memory/ directory which i have included in CRON entry... I get the $used_memory value...I am just not getting the total_memory_kb and used_memory value through CRON...

---------- Post updated at 01:01 PM ---------- Previous update was at 12:23 PM ----------

sorry to rectify the above note:-

can you please explain what you mean by "absolute pathnames in your script"

I have the script in /domain/appplication/memory/ directory which i have included in CRON entry... I get the $free_memory value...I am just not getting the total_memory_kb and used_memory value through CRON...

Try sourcing your .profile in the script. Cron does not automatically source profiles. Different shells use different profiles. I'm assuming you have the Korne shell as your default since you are using ksh in your script. So my example is directed toward the use of the Korne shell as a default shell.

#!/bin/ksh

#
# Source the users profile.
#
# NOTE: There is a space between the first dot (.) and the tilde (~)
#
. ~/.profile

date_var=`date "+%Y%m%d%H%M%S"`
memory_file_name=Mem-"$date_var".csv

cheers!!! mate its working now....Many thanks for your suggestion.

Beware that in most versions of "vmstat" the first line of figures are garbage.

Better to sample for a minute and take the last line only.

vmstat 30 2