Last active
April 20, 2016 10:28
-
-
Save optyler/a078b94616e71495ab1e to your computer and use it in GitHub Desktop.
Generate csv files bases on result of sql files and send it by email
This file contains 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
#!/usr/bin/bash | |
# directories | |
_time_stamp=$(date +%Y-%m-%d-%T) | |
_dir="${1:-${PWD}}" | |
_output_folder="$_dir/$_time_stamp" | |
# mysql | |
_mysql_user=user | |
_mysql_pass=user_pwd | |
# send mail | |
mkdir -p $_output_folder | |
[ ! -d "$_output_folder" ] && { echo "Error: Directory $_output_folder not found."; exit 2; } | |
for sqlfile in *sql | |
do | |
echo "calcule de $sqlfile" | |
mysql --batch --user=$_mysql_user --password=$_mysql_pass < $sqlfile | \ | |
sed "s/'/\'/;s/\t/\",\"/g;s/^/\"/;s/$/\"/;s/\n//g" \ | |
> "$_output_folder/$sqlfile.csv" | |
done | |
# envoi avec piece jointe | |
# option 1 | |
# file=filename_or_filepath;uuencode $file $file|mail -s "optional subject" email_address | |
# option 2 | |
# echo "This is the message body" | mutt -a "/path/to/file.to.attach" -s "subject of message" -- recipient@domain.com | |
# option 3 | |
# mailx -s "Sending Files" -a First_Attachment -a Second_Attachment Recipient@myemail.com | |
# option 4 | |
# http://caspian.dotconf.net/menu/Software/SendEmail/ | |
# sendemail -t to@some.one -m "Here are your files!" -a file1.jpg file2.zip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment