我想创建一个能够通过电子邮件发送日志文件的脚本。现在的问题是我通过电子邮件收到的文本文件是空白的。是哪一部分出了问题?
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="[email protected]"
(
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
三通/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--
这是我仅从电子邮件中收到的内容 https://drive.google.com/file/d/1jnNuezyWxYAdNW_ZZ9ZvG1MG3ZJFLaBc/view?usp=sharing
答案1
内容处置:附件;文件名=“corpsoDB.txt” 结尾 猫/tmp/corpsoDB.txt
您应该在正文部分标题和正文部分内容之间生成换行符。