0

I want to create a script which able to send the log file by email. The problem now is the text file I have received through email is blank. Which part is the problem?

MYSQL_SLOW_LOG_USER="****"
MYSQL_SLOW_LOG_PASSWORD="*****"

SLOW_LOG="/var/log/mysql-slow.log"

cat <<EOF | mysql -u $MYSQL_SLOW_LOG_USER -p$MYSQL_SLOW_LOG_PASSWORD
SET GLOBAL log_queries_not_using_indexes = 'OFF';
SET GLOBAL slow_query_log = 'OFF';
FLUSH SLOW LOGS;
EOF

cat $SLOW_LOG > /tmp/corpsoDB.txt

recipient="cronjobauto@yahoo.com"

(
cat - <<END
Subject: MySQL Slow Query Log Report-Corpso
Content-Type: multipart/mixed; boundary="-omgemailslikewhoa"

GET ON IT.

---omgemailslikewhoa
Content-Type: text/plain; name="corpsoDB.txt"
Content-Disposition: attachment; filename="corpsoDB.txt"
END

cat /tmp/corpsoDB.txt

cat <<END
---omgemailslikewhoa--

END
) | /usr/sbin/sendmail -i -- $recipient

/tmp/corpsoDB.txt

/usr/sbin/mysqld, Version: 5.7.31-log (MySQL Community Server (GPL)). started w$
Tcp port: 0  Unix socket: /var/lib/mysql/mysql.sock
Time                 Id Command    Argument

tee /tmp/sendmail-input.txt

Subject: MySQL Slow Query Log Report-Corpso
Content-Type: multipart/mixed; boundary="-omgemailslikewhoa"

---omgemailslikewhoa
Content-Type: text/plain
Content-Disposition: inline

GET ON IT.

---omgemailslikewhoa
Content-Type: text/plain; name="corpsoDB.txt"
Content-Disposition: attachment; filename="corpsoDB.txt"
/usr/sbin/mysqld, Version: 5.7.31-log (MySQL Community Server (GPL)). started w$
Tcp port: 0  Unix socket: /var/lib/mysql/mysql.sock
Time                 Id Command    Argument
---omgemailslikewhoa--

This is what I have only received from the email https://drive.google.com/file/d/1jnNuezyWxYAdNW_ZZ9ZvG1MG3ZJFLaBc/view?usp=sharing

1
  • 1
    You'd almost certainly be better off using mpack (pack a file in MIME format) rather than rolling your own MIME-handling code
    – roaima
    Sep 14, 2020 at 10:11

1 Answer 1

1
Content-Disposition: attachment; filename="corpsoDB.txt"
END

cat /tmp/corpsoDB.txt

You should be generating a newline between the bodypart headers and the bodypart content.

2
  • sorry, I am new to this. How to generate newline between the bodypart headers and the bodypart content?
    – user432752
    Sep 15, 2020 at 1:46
  • The same way that you did between the message headers and body only 5 lines before that.
    – JdeBP
    Sep 15, 2020 at 4:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.