【发布时间】:2011-11-16 01:40:52
【问题描述】:
我有以下脚本(它连接到 oracle 数据库,查找应用的 arclog 并将其删除):
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
当我自己启动它时它工作正常。但想法是从 cron 开始。 Cron 在尝试启动此脚本时出错:
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
看起来像是转义符号的问题。但我不知道我必须逃避什么。
顺便说一句,当我将脚本分成两部分时,脚本可以与 cron 一起使用:
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
和 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;
但我想把它合二为一。有人可以帮忙吗?
【问题讨论】:
-
向我们展示您在 crontab 中放入的行。
-
在cron输出的第二行
if [ -e /arclogs/arcs.sh ]; then sh -x /arclogs/arcs.sh; fi -
尝试将
<<EOF更改为<<'EOF'。这应该可以防止 shell 解释此处文档中的任何内容。 -
请参阅我的回答中的编辑 2。尝试将 'YES' 放在双引号内:“'YES'”。
-
将
<<EOF更改为<<'EOF'没有帮助。