Error in the Script.

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Error in the Script.
# 1  
Old 11-23-2017
Error in the Script.

Hi, When i am trying to run the script which was prepared for sending the SQL output through mail body and attachment iam getting an error

String """missing terminating quote(").
SP2-0734: unknown command begining" DECODE(SUB.."- restof line ignored.
Code:
#!/bin/bash

CSV="/authlistener/ProdA/service/queryRS.csv"
OP="/authlistener/ProdA/service/queryRS.html"

att_csv="/authlistener/ProdA/service/attchment.csv"
att_op="/authlistener/ProdA/service/attachment.html"
to="venkata.maddela@cgi.com"
subject="Daily Report"
boundary="ZZ_/afg6432dfgkl.94531q"
QUERY="SELECT DECODE(SUBSTR(TRAN.iin,5,2),'25','34',mbr.mbr_no) Country_No,
       DECODE(SUBSTR(TRAN.iin,5,2),'25','Hungary',mbr.name) Country_Name,
    CASE TRAN.DENY_fLAG
    WHEN 'N' THEN 'Approved'
    ELSE 'Declined'
   END Status,
     SUM (TRAN.TRAN_AMOUNT) TOTAL_AMOUNT, COUNT(*) TOTALTRANSACTIONS
     FROM TRAN
     LEFT OUTER JOIN MBR ON substr(TRAN.iin,5,2)    = (MBR.mbr_no)
     LEFT OUTER JOIN CONDITION ON TRAN.CONDITION_ID = condition.condition_id
         WHERE POST_DATE BETWEEN  TO_DATE('20170601', 'yyyymmdd')
      AND  TO_DATE('20170630', 'yyyymmdd')
      AND  TRAN.post_ts  BETWEEN TO_DATE('01 JUN 2017 00:00:00', 'DD MON YYYY HH24:MI:SS') AND TO_DATE('30 JUN 2017 23:59:59', 'DD MON YYYY HH24:MI:SS')
     GROUP BY DECODE(SUBSTR(TRAN.iin,5,2),'25','34',mbr.mbr_no),
                  DECODE(SUBSTR(TRAN.iin,5,2),'25','Hungary',mbr.name),
                          TRAN.DENY_fLAG
         ORDER BY Country_Name;"

att_query="SELECT DECODE(SUBSTR(TRAN.iin,5,2),'25','34',mbr.mbr_no) Country_No,
       DECODE(SUBSTR(TRAN.iin,5,2),'25','Hungary',mbr.name) Country_Name,
    CASE TRAN.DENY_fLAG
    WHEN 'N' THEN 'Approved'
    ELSE 'Declined'
   END Status,
     SUM (TRAN.TRAN_AMOUNT) TOTAL_AMOUNT, COUNT(*) TOTALTRANSACTIONS
     FROM TRAN
     LEFT OUTER JOIN MBR ON substr(TRAN.iin,5,2)    = (MBR.mbr_no)
     LEFT OUTER JOIN CONDITION ON TRAN.CONDITION_ID = condition.condition_id
         WHERE POST_DATE BETWEEN  TO_DATE('20170601', 'yyyymmdd')
      AND  TO_DATE('20170630', 'yyyymmdd')
      AND  TRAN.post_ts  BETWEEN TO_DATE('01 JUN 2017 00:00:00', 'DD MON YYYY HH24:MI:SS') AND TO_DATE('30 JUN 2017 23:59:59', 'DD MON YYYY HH24:MI:SS')
     GROUP BY DECODE(SUBSTR(TRAN.iin,5,2),'25','34',mbr.mbr_no),
                  DECODE(SUBSTR(TRAN.iin,5,2),'25','Hungary',mbr.name),
                          TRAN.DENY_fLAG
         ORDER BY Country_Name;"
CON_STRING="atlas/atlas@atlasprd"

cat > $OP <<EOF
<!doctype html public �-//w3c//dtd html 4.0 transitional//en�>
<html>
<head>
<style>
table {
    border: 1px solid black;
    border-collapse: collapse;
}
th, td {
    text-align: left;
    padding: 8px;
}
tr:nth-child(even){background-color: #f2f2f2}
th {
    background-color: #4CAF50;
    color: white;
}
</style>
</head>
<body>
EOF

cat > $att_op <<EOF
<!doctype html public �-//w3c//dtd html 4.0 transitional//en�>
<html>
<head>
<style>
table {
    border: 1px solid black;
    border-collapse: collapse;
}
th, td {
    text-align: left;
    padding: 8px;
}
tr:nth-child(even){background-color: #f2f2f2}
th {
if(document.getElementById("STATUS").value='APPROVED'){
    background-color: #4CAF50
        }else{
        background-color: red
        }
    color: white;
}
</style>
</head>
<body>
EOF

#Function to fetch the result set from the query
getResultSet()
{
echo $2
#echo -e "Query :=========>"$QUERY
sqlplus -s $CON_STRING <<EOF
set term off
set echo off
set underline off
set pagesize 0
set sqlprompt "
set lines 1000 pages 1000
set linesize 1000
set colsep ","
set trimspool on
set heading on
set newpage 0
set headsep off
set feedback off
spool $1
$2
spool off
EOF
}

convertCSV2HTML()
{
[ "$#" -ne 1 ] && exit -1

file=$1

echo "<table>"
head -n 1 $file | \
    sed -e 's/^/<tr><th>/' -e 's/,/<\/th><th>/g' -e 's/$/<\/th><\/tr>/'
tail -n +2 $file | \
    sed -e 's/^/<tr><td>/' -e 's/,/<\/td><td>/g' -e 's/$/<\/td><\/tr>/'
echo "</table>"
}

#trigger SQL Script
getResultSet $CSV $QUERY
getResultSet $att_csv $att_query

#Converting CSV to HTML Table format
convertCSV2HTML $CSV >> $OP
convertCSV2HTML $att_csv >> $att_op

#body=`cat $OP`

get_mimetype(){
  # warning: assumes that the passed file exists
  file --mime "$1" | sed 's/.*: //'
}

sendWithAttachment()
{
declare -a attachments

attachments=( "$1" )
cat $OP
echo
# Build headers
{

printf '%s\n' "From: $from
To: $to
Subject: $subject
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary=\"$boundary\"

--${boundary}
Content-Type: text/plain; charset=\"US-ASCII\"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

$body
"
for file in "${attachments[@]}"; do

  [ ! -f "$file" ] && echo "Warning: attachment $file not found, skipping" >&2 && continue

  mimetype=$(get_mimetype "$file")

  printf '%s\n' "--${boundary}
Content-Type: $mimetype
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=\"$file\"
"

  base64 "$file"
  echo
done

# print last boundary with closing --
printf '%s\n' "--${boundary}--"

} | sendmail -t -oi   #to send email with attachment as html
}

sendWithAttachment $att_op

# 2  
Old 11-23-2017
Put variables in command arguments in "quotes"!
For example
Code:
echo "$2"

Code:
getResultSet "$CSV" "$QUERY"
getResultSet "$att_csv" "$att_query"

Reason: the shell tries all kinds of substitutions on command arguments.
This User Gave Thanks to MadeInGermany For This Post:
# 3  
Old 11-23-2017
Thank you.... it is working...

---------- Post updated at 02:23 AM ---------- Previous update was at 02:06 AM ----------

Not able to receive the mail...

---------- Post updated at 02:27 AM ---------- Previous update was at 02:23 AM ----------

mail not sent even the script run successfully.
# 4  
Old 11-23-2017
Run the script in debug mode:
Code:
bash -x /path/to/script

.
Alternatively, in the script you can turn diagnostic on with
Code:
set -x

and turn off with
Code:
set +x

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script with sql script error

Hi All when I execute from psql prompt, I get the result, when I try to automate using a shell script, the query is not working # `/usr/bin/psql -U postgres -d coba1 -c "select name from users where "Date" > current_date - 30;"` ERROR: column "Date" does not exist LINE 1: select... (2 Replies)
Discussion started by: srilinux09
2 Replies

2. Shell Programming and Scripting

Calling shell script within awk script throws error

I am getting the following error while passing parameter to a shell script called within awk script. Any idea what's causing this issue and how to ix it ? Thanks sh: -c: line 0: syntax error near unexpected token `newline' sh: -c: line 0: `./billdatecalc.sh ... (10 Replies)
Discussion started by: Sudhakar333
10 Replies

3. Shell Programming and Scripting

Help with FTP Script which is causing "syntax error: unexpected end of file" Error

Hi All, Please hav a look at the below peice of script and let me know if there are any syntax errors. i found that the below peice of Script is causing issue. when i use SFTP its working fine, but there is a demand to use FTP only. please find below code and explain if anything is wrong... (1 Reply)
Discussion started by: mahi_mayu069
1 Replies

4. Shell Programming and Scripting

Error in calling a shell script from another script

HI, We are using two shell scripts, script.sh,env.sh, where env.sh will be called inside script.sh. The variable inside env.sh is used as $var in script.sh.But while running the script its not identifying that variable. Is there any permission needed to call a script inside another script. ... (3 Replies)
Discussion started by: banupriyat
3 Replies

5. UNIX for Dummies Questions & Answers

Re: Script Error [syntax error at line]

Hi , I Have Written A Simple Script To Check Greatest Of '2' Number When Execuating The Script I Am Getting The Below Error SP11: if:not found SP11: line 4:syntax error at line 5:'then' unexpexted And The Program I Have Wrriten For This #!bin/ksh echo "Enter Two Numbers"... (3 Replies)
Discussion started by: anudeepkumar123
3 Replies

6. Shell Programming and Scripting

Syntax error calling TCL script from shell script

hello everyone i am beginner on shell scripting .and i am working on my project work on ad hoc network i wrote a batch (.sh) to do a looping and execute a tcl script i wrote before in each iteration ..but i got this problem " syntax error near unexpected token `('... (1 Reply)
Discussion started by: marcoss90
1 Replies

7. Shell Programming and Scripting

How to grep sql error in shell script and exit the script?

I need help in the following script. I want to grep the sql errors insert into the error table and exit the shell script if there is any error, otherwise keep running the scripts. Here is my script #!/bin/csh -f source .orapass set user = $USER set pass = $PASS cd /opt/data/scripts echo... (2 Replies)
Discussion started by: allinshell99
2 Replies

8. Windows & DOS: Issues & Discussions

Error opening script file - location error

Hello, I know nothing about UNIX, ftp, etc. I am building an excel VBA macro which calls a .bat file. I've taken a pre-existing batch file and am trying to modify it to fit my purposes. I would be very grateful for some assistance. Here is my .bat file: echo off set... (9 Replies)
Discussion started by: starcraftbud
9 Replies

9. Shell Programming and Scripting

Script with error output but continuation in script?

I have written a basic fetching script. The script logs into an FTP site, downloads a .zip file, then unzips and moves the files to the necessary folders, then deletes them, etc. The problem I have is if one of the files no longer exists on the FTP site or another part of the script fails, then... (3 Replies)
Discussion started by: daem0n
3 Replies

10. UNIX for Dummies Questions & Answers

awk Shell Script error : "Syntax Error : `Split' unexpected

hi there i write one awk script file in shell programing the code is related to dd/mm/yy to month, day year format but i get an error please can anybody help me out in this problem ?????? i give my code here including error awk ` # date-month -- convert mm/dd/yy to month day,... (2 Replies)
Discussion started by: Herry
2 Replies
Login or Register to Ask a Question