Last active
April 12, 2019 23:15
-
-
Save technicalogical/4316f79e6a0e9b526b0920ab219ffbdf to your computer and use it in GitHub Desktop.
Script to send out flowuses table on a daily basis.
This file contains hidden or 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 | |
################################################# | |
### 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="[email protected] (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