How do I send a file as an email attachment using Linux command line?

后端 未结 26 2532
盖世英雄少女心
盖世英雄少女心 2020-11-22 04:39

I\'ve created a script that runs every night on my Linux server that uses mysqldump to back up each of my MySQL databases to .sql files and packages them togeth

26条回答
  •  名媛妹妹
    2020-11-22 05:27

    This is how I am doing with one large log file in CentOS:

    MAIL="`whereis mail | awk '{print $2}'`"
    WHOAMI="`whoami`"
    HOSTNAME="`hostname`"
    EMAIL"your@email.address"
    LOGDIR="/var/log/aide"
    LOGNAME="`basename "$0"`_`date "+%Y%m%d_%H%M"`"
    # Arhiveerime ning kui hästi, saadame edasi:
    /bin/tar -zcvf ${LOGDIR}/${LOGNAME}.tgz "${LOGDIR}/${LOGNAME}.log" > /dev/null 2>&1
    if [ $? -eq 0 ]; then
        cd ${LOGDIR}
        # This works too. The message content will be taken from text file below
        # echo 'Hello!' >/root/scripts/audit_check.sh.txt
        # echo "Arhiivifail manuses" | ${MAIL} -s "${HOSTNAME} Aide report" -q /root/scripts/audit_check.sh.txt -a ${LOGNAME}.tgz -S from=${WHOAMI}@${HOSTNAME} ${EMAIL}
        echo "Arhiivifail manuses" | ${MAIL} -s "${HOSTNAME} Aide report" -a ${LOGNAME}.tgz -S from=${WHOAMI}@${HOSTNAME} ${EMAIL}
        /bin/rm "${LOGDIR}/${LOGNAME}.log"
    fi
    

提交回复
热议问题