0

I have a BASH script like the below:

#!/bin/bash

email_template="Subject: Subject
From: [email protected]
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.)?

1

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.