linux - 从 crontab 运行时找不到 Sqlplus 命令

标签 linux oracle bash cron

是这样的,我在rman中做了3个文件来执行备份数据库命令

测试.sh:

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

conectar.sql:

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

备份.sh:

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

然后我对文件执行了所有 chmod u+x 操作,使它们可执行,然后 export EDITOR=nano 更改 cron 编辑器。

当我进入crontab -e i put

00 15 * * * /u01/test.sh

如果我手动点击这个 test.sh,操作会正常运行,但是在 crontab 中我会收到“你收到一封邮件”的消息

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"

你能为我重新制作脚本或 crontab 吗?如果您能回答我的确切修改,我将不胜感激,我不是这个环境的专家,所以一般需要知识的答案会让我保持原样,谢谢。

最佳答案

您可以通过多种方式做到这一点:

  1. 就在 cron 行之前:

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

  2. 或者在 cron 行本身:

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

  3. 让您的脚本 test.sh 使用另一个共享脚本来设置您的 Oracle 环境:

    source/path/to/oracle_env.sh

我更喜欢第三种方法,因为它非常灵活并且可以帮助我们保持 crontab 的整洁。 .bash_profile 应该只用于交互式 shell - 与预定脚本共享它是不好的,尤其是在生产中。

关于linux - 从 crontab 运行时找不到 Sqlplus 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41302304/

相关文章:

python - e2fsprogs/e2fslibs 是否有可用的 python bindinds?

python - 为什么 UniCurses for Python 不起作用?

linux - 在 Linux Mint 17.3 (rosa) 中安装最新的 Postgres (11.1) 失败

python - 作为子进程 1 运行连续脚本,直到子进程 2 中的循环完成

linux - 从 bash 输出中排除一个字符串

sql - REGEXP_REPLACE 不会发生连续模式替换

sql - ORACLE:解释插入计划

SQL SELECT 在父亲 ID 组织树中查找循环引用?

linux - 测试 systemd 单元是否在 bash 脚本中处于事件状态

bash while 循环在第一行之后中断