无法从 CRON 运行 sql 查询
unable to run sql query from CRON
我需要将我的脚本添加到 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" xyz@yahoo.com
exit
我面临的问题是,脚本没有连接到 sqlprompt。
我目前正在收到邮件。但是查询的输出没有被读取。所以我的邮件正文是空白的。
我找到了解决方案。只需为除 bash 以外的任何 shell 提供 ~./profile,为 bash shell 提供 ~./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" xyz@yahoo.com
exit
我需要将我的脚本添加到 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" xyz@yahoo.com
exit
我面临的问题是,脚本没有连接到 sqlprompt。 我目前正在收到邮件。但是查询的输出没有被读取。所以我的邮件正文是空白的。
我找到了解决方案。只需为除 bash 以外的任何 shell 提供 ~./profile,为 bash shell 提供 ~./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" xyz@yahoo.com
exit