日期:2014-05-17  浏览次数:21006 次

oracle 10g 在linux下自动备份问题
我的问题:
 我在我的oracle用户下有backup.sh文件
oracle@localhost zgh]$ pwd
/u01/app/oracle/zgh

  oracle@localhost zgh]$ ll
total 16
-rw-r--r-- 1 oracle oinstall 417 Mar 7 13:09 backup_lv0.sql
-rw-r--r-- 1 oracle oinstall 252 Mar 7 13:14 backup_lv1.sql
-rw-r--r-- 1 oracle oinstall 252 Mar 7 13:14 backup_lv2.sql
-rwxr-xr-x 1 oracle oinstall 941 Mar 7 23:16 backup.sh
  权限也是可以执行的
[oracle@localhost zgh]$ strings backup.sh 
#!/bin/bash
#edit: zgh
#date:2012-03-07
#auto backup database
#load Environment variables
source /u01/app/oracle/.bash_profile
myweek='date+%a'
mydate='date_%Y%m%d'
mydir=/u01/app/oracle/zgh
#Sunday
if ["$myweek"=="Sun"]; then
rman target / msglog=${mydir}/backup_${mydate}.log cmdfile=${mydir}/backup_lv0.sql
#Monday
if ["$myweek"=="Mon"]; then
rman target / msglog=${mydir}/backup_${mydate}.log cmdfile=${mydir}/backup_lv2.sql
#Tuesday
if ["$myweek"=="Tue"]; then
rman target / msglog=${mydir}/backup_${mydate}.log cmdfile=${mydir}/backup_lv2.sql
#Wednesday
if ["$myweek"=="Wed"]; then
rman target / msglog=${mydir}/backup_${mydate}.log cmdfile=${mydir}/backup_lv1.sql
#Thursday
if ["$myweek"=="Thu"]; then
rman target / msglog=${mydir}/backup_${mydate}.log cmdfile=${mydir}/backup_lv2.sql
#Friday
if ["$myweek"=="Sat"]; then
rman target / msglog=${mydir}/backup_${mydate}.log cmdfile=${mydir}/backup_lv2.sql


[oracle@localhost zgh]$ crontab -e
  28 23 * * * sh /u01/app/oracle/zgh/backup.sh

然后得到了这样的mail
[root@localhost mail]# ll
total 12
-rw------- 1 oracle mail 12235 Mar 7 23:28 oracle

[root@localhost mail]# strings oracle 
From oracle@localhost.localdomain Wed Mar 7 23:28:02 2012
Return-Path: <oracle@localhost.localdomain>
Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
  by localhost.localdomain (8.13.1/8.13.1) with ESMTP id q27FS1FA008714
  for <oracle@localhost.localdomain>; Wed, 7 Mar 2012 23:28:01 +0800
Received: (from oracle@localhost)
  by localhost.localdomain (8.13.1/8.13.1/Submit) id q27FS1Ff008707;
  Wed, 7 Mar 2012 23:28:01 +0800
Date: Wed, 7 Mar 2012 23:28:01 +0800
Message-Id: <201203071528.q27FS1Ff008707@localhost.localdomain>
From: root@localhost.localdomain (Cron Daemon)
To: oracle@localhost.localdomain
Subject: Cron <oracle@localhost> sh /u01/app/oracle/zgh/backup.sh
Content-Type: text/plain; charset=UTF-8
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/u01/app/oracle>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=oracle>
X-Cron-Env: <USER=oracle>
/u01/app/oracle/zgh/backup.sh: line 12: [date+%a==Sun]: command not found
/u01/app/oracle/zgh/backup.sh: line 17: [date+%a==Mon]: command not found
/u01/app/oracle/zgh/backup.sh: line 22: [date+%a==Tue]: command not found
/u01/app/oracle/zgh/backup.sh: line 27: [date+%a==Wed]: command not found
/u01/app/oracle/zgh/backup.sh: line 32: [date+%a==Thu]: command not found
/u01/app/oracle/zgh/backup.sh: line 37: [date+%a==Sat]: command not found
/u01/app/oracle/zgh/backup.sh: line 41: eof: command not found
这是为什么呀?????求解答

------解决方案--------------------
探讨
myweek='date+%a'
mydate='date_%Y%m%d'

------解决方案--------------------
探讨
引用:
myweek='date+%a'
mydate='date_%Y%m%d'
这两行赋值你都用的单引号,这是不对的,不能