I have a script, running a sql via a function, with input parameters.
my function does execute the select statement and produces the output.
But the output is not being emailed.
{code}
#!/bin/ksh
USER_001P=`cat /var/opt/oracle/USER_001P`
UNUSED_INDEX=/u1/home/oradba/logs/unused_index.txt
SCHEMAS=/u1/home/oradba/logs/schemas.txt
f_get_schema()
{
clear
echo
echo " Unused - Indexes Report (DEL to eXit)"
echo " ------------------------------------------------------"
echo
echo " Schema name for which to report: \c"
}
f_get_email()
{
clear
echo
echo " Unused - Indexes Report (DEL to eXit)"
echo " ------------------------------------------------------"
echo
echo " Schema name for which to report: $i_schema"
echo
echo " Email address to send report to: \c"
}
f_get_yn()
{
clear
echo
echo " Unused - Indexes Report (DEL to eXit)"
echo " ------------------------------------------------------"
echo
echo " Schema name for which to report: $i_schema"
echo
echo " Email address to send report to: $i_email"
echo
echo
echo " Continue (y/n): \c"
}
f_unused_indexes()
{
sqlplus -s $i_schema/$i_schema${USER_001P} <<!
spool $UNUSED_INDEX
set pages 9999;
set heading off;
set verify off;
set feedback off;
set heading on;
select object_name , object_type ,to_char(last_ddl_time, 'DD-MON-YYYY HH24:MI:SS'
) Last_Used
from user_objects
where object_type='INDEX';
exit
spool off;
!
}
f_email_report()
{
i_schema=' '
f_get_schema
read i_schema
i_email=' '
f_get_email
read i_email
while true
do
i_yn='x'
f_get_yn
read i_yn
case "$i_yn" in
"y") ;;
"Y") ;;
"n") ;;
"N") ;;
*) continue
;;
esac
break
done
if [ $i_yn = "n" -o $i_yn = "N" ]; then
exit 0
fi
echo
echo "\tGenerating Report for $i_schema unused indexes and emailing to $i_email..
. \c"
f_unused_indexes
if [ `grep -i -c 'ORA-' $UNUSED_INDEXES` -eq 0 ]; then
echo "Herewith $i_schema indexes " >> $UNUSED_INDEX
#(
#cat <<!
#PLEASE REVIEW LOG FILES FOR ANY ERRORS
#!
#) | /usr/local/bin/mutt -a $UNUSED_INDEXES -s "(sun8) Unused Index Report for $i
_schema" -i $UNUSED_INDEXES $i_email
echo "done"
else
echo "Failed !!!"
fi
echo "\n\t\t Press any key to return to menu: \c"
read i_key
exit
}
f_email_report
{code}
i commented out the email part..as it was not emailing, but its also not exiting??????
any help will be highly appreciated
my function does execute the select statement and produces the output.
But the output is not being emailed.
{code}
#!/bin/ksh
USER_001P=`cat /var/opt/oracle/USER_001P`
UNUSED_INDEX=/u1/home/oradba/logs/unused_index.txt
SCHEMAS=/u1/home/oradba/logs/schemas.txt
f_get_schema()
{
clear
echo
echo " Unused - Indexes Report (DEL to eXit)"
echo " ------------------------------------------------------"
echo
echo " Schema name for which to report: \c"
}
f_get_email()
{
clear
echo
echo " Unused - Indexes Report (DEL to eXit)"
echo " ------------------------------------------------------"
echo
echo " Schema name for which to report: $i_schema"
echo
echo " Email address to send report to: \c"
}
f_get_yn()
{
clear
echo
echo " Unused - Indexes Report (DEL to eXit)"
echo " ------------------------------------------------------"
echo
echo " Schema name for which to report: $i_schema"
echo
echo " Email address to send report to: $i_email"
echo
echo
echo " Continue (y/n): \c"
}
f_unused_indexes()
{
sqlplus -s $i_schema/$i_schema${USER_001P} <<!
spool $UNUSED_INDEX
set pages 9999;
set heading off;
set verify off;
set feedback off;
set heading on;
select object_name , object_type ,to_char(last_ddl_time, 'DD-MON-YYYY HH24:MI:SS'
) Last_Used
from user_objects
where object_type='INDEX';
exit
spool off;
!
}
f_email_report()
{
i_schema=' '
f_get_schema
read i_schema
i_email=' '
f_get_email
read i_email
while true
do
i_yn='x'
f_get_yn
read i_yn
case "$i_yn" in
"y") ;;
"Y") ;;
"n") ;;
"N") ;;
*) continue
;;
esac
break
done
if [ $i_yn = "n" -o $i_yn = "N" ]; then
exit 0
fi
echo
echo "\tGenerating Report for $i_schema unused indexes and emailing to $i_email..
. \c"
f_unused_indexes
if [ `grep -i -c 'ORA-' $UNUSED_INDEXES` -eq 0 ]; then
echo "Herewith $i_schema indexes " >> $UNUSED_INDEX
#(
#cat <<!
#PLEASE REVIEW LOG FILES FOR ANY ERRORS
#!
#) | /usr/local/bin/mutt -a $UNUSED_INDEXES -s "(sun8) Unused Index Report for $i
_schema" -i $UNUSED_INDEXES $i_email
echo "done"
else
echo "Failed !!!"
fi
echo "\n\t\t Press any key to return to menu: \c"
read i_key
exit
}
f_email_report
{code}
i commented out the email part..as it was not emailing, but its also not exiting??????
any help will be highly appreciated