postgres 9.6 Debian GNU/Linux 9
is use following simplyfied bash script wich gets called from a users crontab, myid is a passed parameter:
#!/bin/bash
...
PGPASSFILE="/home/user/.pgpass"
PGCONNECT=" psql -U myuser -w -h 000.000.000.000 -d mydatabase -p 5432"
PGCOMMAND1="SELECT something, somemmore FROM schema.table WHERE id= ${myid}"
PGRESULT=`$PGCONNECT -A -F ";" -t -c "$PGCOMMAND1"`
RETCODE1=$?
...
PGCOMMAND2="SELECT schema.functionname(${myid});"
PGRESULT=`$PGCONNECT -A -F ";" -t -c "$PGCOMMAND2"`
RETCODE2=$?
if [ $RETCODE1 -eq 0 ] && [ $RETCODE2 -eq 0 ]; then
mailx -s sendme_asuccessemail
else
echo -e "ret1: $RETCODE1\n" >> $MAIL_FILE
echo -e "ret2: $RETCODE2\n" >> $MAIL_FILE
mailx -s sendme_errormailwith retcode1=2
fi
and most of the time all is ok ( the script runs 60 times a day to different times ). once per week or less i get a errormail with psql exit status 2 in RETCODE1 as a result of the select.
from the manpage:
2 if the connection to the server went bad and the session was not
interactive
it may happen, this script is called per usercrontab, that it gets executeted twice or more on the same time with different myid. The second command always gets called, which does the real work.
How can i narrow down the error ? What does the error realy mean ? Can i ignore it ?