[英]Bash script with multiline heredoc doesn't output anything
我正在编写一个脚本以在邮件中发送 SQL output,但它没有成功执行并且没有生成我想要的 output。
该查询生成具有多行的两列。 如何以如下表格格式生成 output?
下面是我的代码:
#!/bin/bash
ORACLE_HOME= **PATH
export ORACLE_HOME
PATH=$PATH:$ORACLE_HOME/bin
export PATH
TNS_ADMIN= ** PATH
export TNS_ADMIN
today=$(date +%d-%m-%Y)
output=$(sqlplus -S user/pass@service <<EOF
set heading off;
SELECT distinct list_name ,max(captured_dttm) as Last_received FROM db.table1
group by list_name having max(captured_dttm) <= trunc(sysdate - interval '2' hour);
EOF)
if [ -z "$output" ];
then
echo"its fine"
exit
else
echo "
Dear All,
Kindly check we've not received the list for last 2 hour : $output
Regards,
Team" | mailx -S smtp=XX.XX.X.XX:XX -s "URGENT! Please check list FOR $today" user@abc.com
fi
使用 here 文档时,结束字符串后面不能跟任何内容,只能是换行符。 将右括号移到下一行:
output=$(sqlplus -S user/pass@service <<EOF
...
EOF
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.