0

This is the case, I made 3 files to execute backup database command in rman

test.sh:

#!/bin/bash
sqlplus /nolog @/u01/conectar.sql

conectar.sql:

connect sys/manager as sysdba
ho rman target mydatabase/mypassword @/u01/backup.sh

backup.sh:

#!/bin/bash
RUN {backup database;}

and then I did all the chmod u+x for the files to make them executable, then export EDITOR=nano to change the cron editor.

when I go to crontab -e i put

00 15 * * * /u01/test.sh

If I clic this test.sh manually, the operation runs normally, but then in the crontab I get the "you got a mail" thing with this message

From root@localhost.localdomain Thu Dec 22 16:20:01 2016 Return-Path: X-Original-To: oracle Delivered-To: oracle@localhost.localdomain Received: by localhost.localdomain (Postfix, from userid 500) id 956CD41D4B; Thu, 22 Dec 2016 16:20:01 -0400 (AST) From: root@localhost.localdomain (Cron Daemon) To: oracle@localhost.localdomain Subject: Cron /u01/test.sh Content-Type: text/plain; charset=UTF-8 Auto-Submitted: auto-generated X-Cron-Env: X-Cron-Env: X-Cron-Env: X-Cron-Env: X-Cron-Env: Message-Id: <20161222202001.956CD41D4B@localhost.localdomain> Date: Thu, 22 Dec 2016 16:20:01 -0400 (AST) /u01/test.sh: line 3: sqlplus: command not found"

Please can you remake the script or the crontab for me? If you can answer with the exactly modifications I would appreciate it, I'm not an expert in this environment so a general knowledge needed answer will leave me the same, thanks.

pacholik
  • 8,607
  • 9
  • 43
  • 55
Robenya
  • 9
  • 2
  • 5
  • 2
    Try to set set PATH for `ORACLE_HOME/bin` or just run SQL*PLUS as `ORACLE_HOME/bin/sqlplus `. – atokpas Dec 23 '16 at 13:31
  • thanks, now where should i add `ORACLE_HOME/bin` or what to do specifically? – Robenya Dec 23 '16 at 13:36
  • [Possible duplicate](http://stackoverflow.com/q/2229825/266304), or at least related. You need to set up the Oracle environment in your bash script - possibly by sourcing your existing `~/.bash_profile`; or you can source that as part of the crontab entry (shown in an answer on that question). – Alex Poole Dec 23 '16 at 13:37
  • ok, what file do i need to modify in order to do that? – Robenya Dec 23 '16 at 13:42
  • 1
    @Robenya : In your bash script. – atokpas Dec 23 '16 at 13:50

1 Answers1

2

You can do it in many ways:

  1. Just before the cron line:

    PATH=$PATH:/full/path/to/oracle/bin

  2. Or on the cron line itself:

    00 15 * * * PATH=$PATH:/full/path/to/oracle/bin /u01/test.sh

  3. Let your script test.sh source another shared script that sets up your Oracle environment:

    source /path/to/oracle_env.sh

I prefer the third method because it is very flexible and it helps us keep the crontab uncluttered. .bash_profile should be meant for interactive shell only - it is not good to share it with scheduled scripts, especially in production.

codeforester
  • 39,467
  • 16
  • 112
  • 140
  • Hi @codeforester, tried to locate oracle_env.sh and couldn't find it, can You help me in that please? – Robenya Jan 04 '17 at 19:04