I have the following script (it connects to oracle database, looking for applied arclogs and deletes it):
ARCLOGS=$(/oracle/base11202/11202/bin/sqlplus -s / as sysdba <<EOF
set head off
set verify off
set feedback off
select name from v$archived_log where applied = 'YES' and first_time > sysdate - 1 order by sequence#;
exit;
EOF)
echo "${ARCLOGS}" | while read arc
do
if [[ -e $arc ]]
then
rm -f $arc
fi
done
It works fine when i start it by myself. But the idea is to start it with cron. Cron gives errors when trying to start this script:
Your "cron" job executed on test on Mon Nov 14 15:17:00 2011 if [ -e /arclogs/arcs.sh ]; then sh -x /arclogs/arcs.sh; fi produced the following output: + + /oracle/base11202/bin/sqlplus -s / as sysdba + 0<< set head off set verify off set feedback off select name from v$archived_log where applied = "YES" and first_time > sysdate - 1 order by sequence#; exit; ARCLOGS=select name from v$archived_log where applied = "YES" and first_time > sysdate - 1 order by sequence# * ERROR at line 1: ORA-00904: "YES": invalid identifier + read arc + echo select name from v$archived_log where applied = "YES" and first_time > sysdate - 1 order by sequence# * ERROR at line 1: ORA-00904: "YES": invalid identifier + [[ -e select name from v$archived_log where applied = "YES" and first_time > sysdate - 1 order by sequence# ]] + read arc + [[ -e * ]] + read arc + [[ -e ERROR at line 1: ]] + read arc + [[ -e ORA-00904: "YES": invalid identifier ]] + read arc
Looks like the problem with escaping symbols. But i have no idea what i have to escape.
Btw, the scripts works with cron when i split it in two pieces:
arcs.sh:
ARCLOGS=$(/oracle/base11202/bin/sqlplus -s / as sysdba <<EOF
set head off
set verify off
set feedback off
select name from v$archived_log where applied = 'YES' and first_time > sysdate - 1 order by sequence#;
exit;
EOF)
echo "${ARCLOGS}" | while read arc
do
if [[ -e $arc ]]
then
rm -f $arc
fi
done
and arcs.sql:
connect / as sysdba
set head off
set verify off
set feedback off
select name from v$archived_log where applied = 'YES' and first_time > sysdate - 1 order by sequence#;
exit;
But i want to have it in one piece. Can someone, please, help?
Just taking a shot in the dark. Try calling /bin/bash explicity from your cron line. Cron executes with sh by default.