简体   繁体   中英

Bash script with multiline heredoc doesn't output anything

I'm writing a script to send SQL output in mail, but it is not executing successfully and is not generating the output I want.

The query generates two columns with multiple rows. How can I generate the output in table format as below?

列列表名的表|最后收到

Below is my code:

#!/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

When using a here document, the closing string can't be followed by anything but a newline. Move the closing parenthesis to the next line:

output=$(sqlplus -S user/pass@service <<EOF
...
EOF
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM