Aishwarya Mishra
Aishwarya Mishra

Reputation: 45

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?

table with columns listname | last received

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"   [email protected]
fi

Upvotes: 0

Views: 341

Answers (1)

choroba
choroba

Reputation: 241808

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
)

Upvotes: 4

Related Questions