目录
1、问题:Oracle Linux 7.4的EBS用户orauat1,无法执行crontab问题排查
2、过程:
(1)在orauat1用户下创建脚本:
[orauat1@ebsmesuatstd scripts]$ vi del_archivelog.sh #!/bin/bash rman target / msglog '/u01/uat1/rmanlog/test.log' <<EOF run{ crosscheck archivelog all; delete expired archivelog all; delete noprompt archivelog until time 'sysdate-2'; } exit EOF
手动测试脚本ok:
sh /u01/uat1/scripts/del_archivelog.sh
(2)创建crontab计划
14 11 * * * /bin/bash /u01/uat1/scripts/del_archivelog.sh >/dev/null
(3)到点发现并未执行
3、检查
(1)查看crontab 日志,发现已经执行了crontab计划
[root@ebsmesuatstd ~]# tail -100f /var/log/cron Aug 3 11:14:01 EBSMESUATSTD crond[31765]: (orauat1) RELOAD (/var/spool/cron/orauat1) Aug 3 11:14:01 EBSMESUATSTD CROND[928]: (orauat1) CMD (/bin/bash /u01/uat1/scripts/del_archivelog.sh >/dev/null)
(2)再查看/var/spool/cron/orauat1
[root@ebsmesuatstd ~]# tail -100f /var/spool/cron/orauat1 14 11 * * * /bin/bash /u01/uat1/scripts/del_archivelog.sh >/dev/null
(3)再查看/var/spool/mail/orauat1
[orauat1@ebsmesuatstd scripts]$ tail -10f /var/spool/mail/orauat1 Message-Id: <20210803031101.5631C1A4E3B@ebsmesuatstd.localdomain> Date: Tue, 3 Aug 2021 11:11:01 +0800 (CST) /u01/uat1/scripts/del_archivelog.sh: line 3: rman: command not found
4、结论:
发现是执行脚本后,rman命令不识别,考虑到时环境变量问题。
5、解决:
在脚本中加入环境变量进行生效。
[orauat1@ebsmesuatstd scripts]$ vi del_archivelog.sh #!/bin/bash #The environment variables take effect for ENV in ~/.bash_profile ~/.profile do if [ -f $ENV ]; then . $ENV fi done rman target / msglog '/u01/uat1/rmanlog/test.log' <<EOF run{ crosscheck archivelog all; delete expired archivelog all; delete noprompt archivelog until time 'sysdate-2'; } exit EOF