0

I have a BASH script like the below:

#!/bin/bash

email_template="Subject: Subject
From: example@example.com
To: %s

%s
%s
%s
"

cat test.out | while read num email limit orders; do
    echo "Sending mail to '$email'"
    printf "$email_template" "$email" "$num" "$limit" "$orders" |
    sendmail -oi -t
done

Also there is a .sql file with a SQL query contained within that does a SPOOL to test.out with results. How can I make it so that this is all done within the BASH script above (SQL in BASH script, no cat etc.)?

user2656114
  • 949
  • 4
  • 18
  • 35
  • 1
    Try the following: sqlplus / @file-with-sql-1.sql Source: http://stackoverflow.com/questions/1467846/how-do-you-execute-sql-from-within-a-bash-script – Yiannis Nennes Aug 09 '13 at 14:14

1 Answers1

0

Without seeing the .sql file it is more difficult to say but here are some possibilities:

Add the .sql inline and store it in a bash variable:

mysqlquery="select * from foo;
selct * from baz;
select * from bar;"

echo "${mysqlquery}"|mysql

If you keep the .sql file separate then you can do something like:

mysql < /path/sqlFile.sql
dtorgo
  • 2,066
  • 1
  • 16
  • 10