below script to automate your stats job
#!/bin/ksh
export ORACLE_SID=APLOD2;
export ORACLE_HOME=/optware/oracle/11.2.0.2/db
export ORACLE_PATH=/optware/oracle/11.2.0.2/db/bin
export PATH=$PATH:$ORACLE_HOME/bin
export LIBPATH=/optware/oracle/11.2.0.2/db/lib:/optware/oracle/11.2.0.2/db/lib32
export DATETIME=`date +%Y%m%d`
sqlplus -s GCD/system11@$APLOD2 <<EOF
spool /tmp/APLOP2_schema_stats_$ DATETIME.log
execute DBMS_STATS.GATHER_SCHEMA_STATS (ownname=> 'GCD', estimate_percent=> 40, method_opt=> 'FOR ALL INDEXED COLUMNS SIZE AUTO', DEGREE=> 12, cascade=>TRUE);
select sysdate from dual;
spool off;
exit
EOF
if [ $? -eq 0 ]
then
mailx -s "APLOD2 Stats Completed" 'dl.gt.global.apollo.dev@imcnam.ssmb.com' < /tmp/APLOD2Stat_$DATETIME.log
else
mailx -s "APLOD2 Stats Error" 'dl.gt.global.apollo.dev@imcnam.ssmb.com' < /tmp/APLOD2Stat_$DATETIME.log
fi
returnStatus=$?
exit ${returnStatus:-0}
EOF
==================
ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified
Enter password:
ERROR:
ORA-12545: Connect failed because target host or object does not exist
need to ask SA setup Oracle TNS on both servers