Skip to content

Instantly share code, notes, and snippets.

@technicalogical
Last active April 12, 2019 23:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save technicalogical/4316f79e6a0e9b526b0920ab219ffbdf to your computer and use it in GitHub Desktop.
Save technicalogical/4316f79e6a0e9b526b0920ab219ffbdf to your computer and use it in GitHub Desktop.
Script to send out flowuses table on a daily basis.
#!/bin/bash
#################################################
### Backup file location and naming variables ###
#################################################
TODAY=`date +"%d%b%Y"`
db_record="flowuses"
filename="db_export_${db_record}_${TODAY}.csv"
dir="/var/lib/mysql/backups/"
headers="/home/steven/backups/headers.csv"
attachedfile="${db_record}_${TODAY}.csv"
####################################################
### Database things, commands, connection string ###
####################################################
hostname="localhost"
user="putthinghere"
password="puthtingshere"
database="putthingshere"
port="3306"
query="SELECT * INTO OUTFILE '$dir$filename' FIELDS ENCLOSED BY '\"' TERMINATED BY ',' FROM $database.$db_record WHERE created_at BETWEEN DATE ( DATE_SUB( NOW() ,
INTERVAL 1 DAY ) ) AND DATE ( NOW() );"
###########################################################################################
### Email Things, here you can change the mailto and mailfrom address, subject, body.. ###
###########################################################################################
mailfrom="flowuses@s132-148-91-202.secureserver.net (Flow Uses)"
mailto="emails seperated by commas "
subject="Good morning from Flow Tool, Sunshine..."
body="Hello, here is a copy of yesterdays flow uses. Download the attachment to view the activity in MS Excel."
echo "${query}" | mysql --host=${hostname} --port=${port} --user=${user} --password=${password} ${database}
cat $headers $dir$filename > $dir$attachedfile
echo "${body}" | mailx -r "${mailfrom}" -s "${subject}" -a $dir$attachedfile $mailto
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment