**** UPDATE ~ binlib points out an easier ( more correct ) way to quote the expression in the post following this one. ******
How do I hide quotes from sqsh and pass the SQL?
---------- Post updated at 06:58 PM ---------- Previous update was at 06:02 PM ----------
Solution ....finally.
Problem:
Protect quoted expression "%wsd%" from bashes prying eyes. sqsh must see it in quotes.
Answer:
SQL="SELECT second_id FROM borrower WHERE btype like '"'%wsd%'"'"
Victory is sweet. Now if I could just get out of this damn valentines banquet I get
conned into every year .....[SIGH]
Thanks ~
Bub
PS: sqsh rocks if you need to deal with Sybase or MS SQL server.
---------- Post updated at 07:14 PM ---------- Previous update was at 06:58 PM ----------
I've seen other SQSH users in this mess while Googling, so here's a tip for
passing queries to SQSH without resorting to external SQL scripts.
Define your query:
SQL="SELECT second_id FROM borrower WHERE btype like '"'%wsd%'"'"
Note carefully the quoting in the expression %wsd%. The expression is surrounded by single quoted double quotes: eg., '"'
while the whole query is surrounded by single quotes ...making
for a quote mess on the end ...eg., '"'" ( thats: single - double - single - double ).
***** EDIT ***** Please see the following two posts ...esp. from Binlib. You can quote the last expression with a single set of single quotes.
Thanks binlib! Tested and true.
Next, run that filthy query like so:
$SQSH="/usr/bin/sqsh"
$SERVER="server.whatever.org"
$USER="username"
$PASS="secrets"
$DB="nameOfDatabase"
$SQSH -S "$SERVER" -U "$USER" -P "$PASS" -D "$DB" -C "$SQL" > $OUT
You don't necessarily need all the variables, but it's a bit easier on
the eyes of those stuck reading it later. I usually define the sqsh
binary for cron, otherwise you'd likely have to define it for the
cron environment. Could be mistaken ...I always try to cron-proof
all but the most common commands. Easier than fixing every cron
environment path variables.
Later ...
Bub
***** UPDATED **** Please see following two posts for simpler quoting option.