error in file writing in crontab

Hi ,
I have a crontab job that is trying to write a file and the read it . But the crontab is not able to create any file . But when i run the script as shell then it runs fine . could you tell me what i am missing here .

Here is the script

cat Tablespace_Monitor_ATG

#!/bin/ksh
PATH=/usr/bin::/jcw-data/home/jcwprodi/sqllib/bin:/jcw-data/home/jcwprodi/sqllib/adm:/jcw-data/home/jcwprodi/sqllib/misc:/bin
DB2INSTANCE=jcwprodi
LD_LIBRARY_PATH=:/usr/lib:/usr/sbin:/usr/bin:/lib
export PATH DB2INSTANCE

db2 -x "connect to atg "

db2 -x "drop table daya.tablespace_info "

db2 -x "create table daya.tablespace_info ( Tblsp_name varchar(15) , size_in_mb bigint ,Per_free_space int, used_size_mb bigint )"

db2 -x "select tablespace_name , int((total_pages*page_size)/(1024*1024)) as Size_in_MB ,smallint((float(free_pages) / float(total_pages))100) as per_free_space, int((used_pages*page_size)/(10241024)) as Used_size_MB from table(SNAPSHOT_TBS_CFG('ATG',-1)) where tablespace_type=0 "

db2 -x "insert into daya.tablespace_info select tablespace_name , int((total_pages*page_size)/(1024*1024)) as Size_in_MB ,smallint((float(free_pages) / float(total_pages))100) as per_free_space, int((used_pages*page_size)/(10241024)) as Used_size_MB from table(SNAPSHOT_TBS_CFG('ATG',-1)) where tablespace_type=0 "

echo "TABLESPACE NAME % FREE SPACE" > Tablespace_info_atg
echo " " >> Tablespace_info_atg
db2 -x "select TBLSP_NAME as Name ,PER_FREE_SPACE as Percentage_use from daya.tablespace_info" > Tablespace_info_atg
# It is failing to create the above file Tablespace_info_atg
chmod 777 Tablespace_info_atg
cat /jcw-data/jcwprodi/CRONTAB/Tablespace_info_atg | mail -s "Tablespace Usage For ATG on WAG-PROD-DBCLUSTER " abc_123@yahoo.com

Thanks in advance

  1. Post the code with code tags for proper visibility.

  2. Thing you may miss is, Give the filename with Absolute Path.

  3. Dont miss to check FAQ here.

I tried to run the same script as higher id ( id added to sudoer file ) and that works fine .
It worked when i had /tmp as the path before i wrote the full path too .

Thanks , it works now :slight_smile: