pg_dump... > dump.sql
if [$? -ne 0];
then
exit 1
fi
scp... && rm dump.sql
usually all the output from a cronjob is sent to you via email so no need for mailx etc.
When pg_dump encounters an error it also should write it to stderr so it won't end up in your dump file. Instead it will be printed to your screen when you run the script manually or get sent to you via mail when it is started as a cronjob
That should work or we just move the scp command
I would do it like this:
usually all the output from a cronjob is sent to you via email so no need for mailx etc.
When pg_dump encounters an error it also should write it to stderr so it won't end up in your dump file. Instead it will be printed to your screen when you run the script manually or get sent to you via mail when it is started as a cronjob
Even shorter solution:
set -o errexit
will cause the script to end as soon as any command fails.