我需要将我的脚本添加到 cronjob。但它没有连接到 sqlprompt 并执行我的查询。Cron 适用于不在 sqlprompt #!/bin/bash 中的其他命令
sql=/instance_name/../product/12102 // ORACLE_HOME loc
connnect=$($sql -s "/ as sysdba" <<EOF
spool h1.txt
select file_name from dba_data_files where tablespace_name='RTSPACE';
spool off;
exit
EOF)
cat "h1.txt" | mail -s "test" [email protected]
exit
我面临的问题是,脚本没有连接到 sqlprompt。我目前正在接收邮件。但是查询的输出没有被读取。所以我的邮件正文是空白的。
我找到了解决方案。对于 bash 以外的任何 shell,只需 source ~./profile ,对于 bash shell 只需 source ~./bash_profile。重定向到 >/dev/null 以防万一出现任何错误。这将连接到您的 sql 提示符。
source ~./bash_profile >/dev/null
source ~./profile >/dev/null
sqlplus -s "/ as sysdba" <<EOF
spool h1.txt
select file_name from dba_data_files where tablespace_name='RTSPACE';
spool off;
exit
EOF)
cat "h1.txt" | mail -s "test" [email protected]
exit
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句