I need help understanding some pieces of a shell script to connect to a Redshift database because Bash/shell is unfamiliar for me.
to use
pgpass, is this all I need to get the credentials? :cat > ./.pgpass <<-CREDS $HOSTNAME:$PORT_NUMBER:$DBNAME:$USERNAME:$PASSWORD CREDSWhat is
<<-? Is it a comment? Quick search says that<<ENDis a comment but is that anything different from<<-CREDS?This is somewhat related to #2, what do
<<-ATOMICand\xmean in this snippet?$PSQL_CMD <<-ATOMIC \x SELECT column1 FROM $THETABLE WHERE column1='true'; ATOMIC
Since ATOMIC is at the end of this block, I would presume that it's stating the end of a block or something, but I don't understand the documentation or anything.
How do I assign the returned value(s) of the
SELECTstatement into a variable and echo it into an email? I have a line to send the email, but don't know how to assign the returned values from theSELECTquery into a variable:$ echo "hello world" | mail -s "Test" [email protected]
I'm not sure what you're trying to do here. To my knowledge,
pgpasswon't contain your credentials unless you've put them in there yourself. This sounds like maybe command to do that.<<-is not a comment. It represents a 'Here document' See: https://en.wikipedia.org/wiki/Here_document#Unix-ShellsRegarding
<<-ATOMICsee the above link. The\xtells psql to format the output from yourSELECT