I have prepared the below script to monitor the tablespace and alert the users whenever it reaches a threshold limit.
#!/bin/sh
. /home/.profile
sqlplus -s $LOGON << .eof > $scripts/check_tablespace.temp
set pages 0
select tablespace_name, free_percent
from (
SELECT b.tablespace_name, b.tablespace_size_mb, sum(nvl(fs.bytes,0))/1024/1024 free_size_mb,
(sum(nvl(fs.bytes,0))/1024/1024/b.tablespace_size_mb *100) free_percent
FROM dba_free_space fs,
(SELECT tablespace_name, sum(bytes)/1024/1024 tablespace_size_mb FROM dba_data_files
GROUP BY tablespace_name
) b
where
fs.tablespace_name like 'INFA_%'
and
fs.tablespace_name = b.tablespace_name
group by b.tablespace_name, b.tablespace_size_mb
) ts_free_percent
WHERE free_percent < 60
ORDER BY free_percent;
exit
eof
cd $scripts
chmod ugo+rw check_tablespace.temp
counter=`cat check_tablespace.temp | sed '/^$/d'| wc -l`
echo "count="$counter
if [ $counter -gt 0 ] then
cat check_tablespace.temp | mailx -s 'Alert: Free tablespace alert' $alertlist
fi
rm check_tablespace.temp
But when I execute the script, it fails with following error.
cat: cannot open check_tablespace.temp
Script creates check_tablespace.temp and when I execute the cat command from commandline, it works fine.
cat check_tablespace.temp
INFA_TS 45.575
Also i tried to change the permissions assuming that it is a permission problem, but still it fails with the same error.
Sam