Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dobrivoje/fd907b914c51cfdfdf8682de05a61817 to your computer and use it in GitHub Desktop.
Save dobrivoje/fd907b914c51cfdfdf8682de05a61817 to your computer and use it in GitHub Desktop.
vacuum.sh
### !/bin/bash
CLIENT="Server name"
DBNAME="postgres_database_Name"
POSTGRESAUTH="postgres"
PGPASSWORD="db password"
MODE=full
TO1="first_email@email.com"
TO2="second_email@email.com"
SUBJ="$CLIENT, baza: $DBNAME, full vacuum završen"
S="$CLIENT - $MODE vaccum for database $DBNAME"
LOG="/root/scripts/logs/vacuum_full.log"
export PGPASSWORD
echo "[`date '+%X'`] Vacuum start, CLIENT: $CLIENT, database: $DBNAME " >> $LOG
### Commands below will send emails and notify users that job has begun
cat "$S - Start" | `sh /root/scripts/mail/posaljimail44.sh $TO1 "$S - Start"`
cat "$S - Start" | `sh /root/scripts/mail/posaljimail44.sh $TO2 "$S - Start"`
### psql $DBNAME -h localhost -U $POSTGRESAUTH -f /root/scripts/vacuum_full.sh >> $LOG
nice -19 vacuumdb --host=localhost --port=5432 --dbname=$DBNAME --username=$POSTGRESAUTH --$MODE --verbose
echo "$S - Finished." >> $LOG
### Commands below will send emails and notify users that job is done
cat $LOG | tail -n 3 | `sh /root/scripts/mail/posaljimail44.sh "$TO1" "$SUBJ" `
cat $LOG | tail -n 3 | `sh /root/scripts/mail/posaljimail44.sh "$TO2" "$SUBJ" `
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment