Last active
August 29, 2015 14:11
-
-
Save dirkjanfaber/ed566afabb06ffd3bf53 to your computer and use it in GitHub Desktop.
pgagent mail job
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
export PGSERVICE=database | |
[email protected] | |
( | |
cat <<__EOT__ | |
<html> | |
<body> | |
<pre> | |
__EOT__ | |
( | |
cat <<__EOT__ | |
\pset linestyle ascii | |
select 'hello world' as message, 42 as answer | |
__EOT__ | |
) |\ | |
psql -q -1 -v ON_ERROR_STOP=1 --pset pager=off | |
cat <<__EOT__ | |
</pre> | |
</body> | |
</html> | |
__EOT__ | |
) |\ | |
mutt -e "set content_type=text/html" ${MAILTO} | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When you want to use pgagent for scheduling within PostgreSQL and want the output to be mailed to you, put the (edited) code into the Definition part of the job in pgAdmin.
The script uses html to format the mailed output.
Note that the script requires a functional
pg_service.conf
and mutt to be installed.