I have a bash script where I execute a Postgres query using psql
client, store the result into a variable and send the result in email using mail
utility.
Below are the bash scripts I have tried. 1:
#!/bin/bash
varresult=`psql -H -A -h host_name -p port -U usr -d mydb -t -c "select rpad(sch_name, 10, ' '), rpad(trs_name, 63, ' '), rpad(trs_type, 11, ' '), comments from table1
;"`
mail -s "testing email" someone@example.com <<< $varresult
2:
#!/bin/bash
mail -s "testing email" someone@example.com <<< `psql -H -A -h host_name -p port -U usr -d mydb -t -c "select rpad(sch_name, 10, ' '), rpad(trs_name, 63, ' '), rpad(trs_type, 11, ' '), comments from table1
;"`
Both the above scripts send same unformatted result set in email. The query result has 4 columns and are appearing without any format in the receiver's email.
So I used rpad
function in the query to align them properly, but in the email the result still looks unformatted. When I copy the email content to a text file, the content looks perfectly formatted.
How the result looks in email:
COL1 | COL2 | COL3
val_t | test_rgt | test cmts apr
val_t | test_t | test cmts
val_tr | test_wgdt | test cmts
val_t | test_hty | test cmts stgr
val_t | test_sf | test cmts gedf
How the result looks in notepad after copy/pasting the above result:
COL1 | COL2 | COL3
val_t | test_rgt | test cmts apr
val_t | test_t | test cmts
val_tr | test_wgdt | test cmts
val_t | test_hty | test cmts stgr
val_t | test_sf | test cmts gedf
Can someone help me on how to make the result look perfectly formatted in email?
Below is the mail
version:
Heirloom Mail version 12.5 7/5/10.