homelab/barbarian/copy.sh

35 lines
1.4 KiB
Bash
Raw Permalink Normal View History

#!/bin/sh
FROM_DIR=$1 # trailing slash
TO_DIR=$2 # trailing slash
2024-03-02 00:45:39 -08:00
LOG_FILE=/mnt/Tank/home/admin/copy.log
2024-03-02 00:45:39 -08:00
rsync -avhW $FROM_DIR $TO_DIR > $LOG_FILE
2022-04-11 21:53:56 -07:00
# If filesize is less than 23 million bytes (21.93 MiB)
# Gives generous headroom for Gmail max attachment size
2024-03-02 00:45:39 -08:00
if [ $(ls -la $LOG_FILE | awk '{print $5}') -le 23000000 ]; then
2022-04-11 21:53:56 -07:00
( echo "Subject: Copy $FROM_DIR to $TO_DIR operation complete."
echo "Mime-Version: 1.0"
echo "Content-Type: multipart/mixed; boundary=\"d29a0c638b540b23e9a29a3a9aebc900aeeb6a82\""
echo "Content-Transfer-Encoding: 7bit"
echo ""
echo "--d29a0c638b540b23e9a29a3a9aebc900aeeb6a82"
echo "Content-Type: text/html; charset=\"UTF-8\""
echo "Content-Transfer-Encoding: 7bit"
echo "Content-Disposition: inline"
echo ""
2024-03-02 00:45:39 -08:00
echo "Copy $FROM_DIR to $TO_DIR complete. See log at $LOG_FILE for details about what was copied."
2022-04-11 21:53:56 -07:00
echo ""
echo "--d29a0c638b540b23e9a29a3a9aebc900aeeb6a82"
echo "Content-Type: text/plain"
echo "Content-Transfer-Encoding: base64"
2024-03-02 00:45:39 -08:00
echo "Content-Disposition: attachment; filename=\"$(basename $LOG_FILE)\""
2022-04-11 21:53:56 -07:00
echo ""
2024-03-02 00:45:39 -08:00
base64 "$LOG_FILE"
2022-04-11 21:53:56 -07:00
echo "--d29a0c638b540b23e9a29a3a9aebc900aeeb6a82--"
2024-03-02 00:45:39 -08:00
echo ""
echo "--d29a0c638b540b23e9a29a3a9aebc900aeeb6a82--"
) | sendmail root
2022-04-11 21:53:56 -07:00
else
2024-03-02 00:45:39 -08:00
echo "Filesize too large to attach. See log file at $LOG_FILE for details." | mail -s "Copy $FROM_DIR to $TO_DIR operation complete." root
2022-04-11 21:53:56 -07:00
fi