通过 crontab 发送电子邮件失败

通过 crontab 发送电子邮件失败

我在 crontab 中放置了一个脚本,当备份脚本完成时,它会向我发送一封电子邮件。

该脚本自行运行时确实会向我发送该电子邮件。

然而,当它在 crontab 中运行时我得到

sendmail: 450 Requested mail action not taken: mailbox unavailable

来自系统日志

Aug 15 03:49:02 7 CRON[5237]: (andy) CMD (/home/andy/bin/Send_Email.sh)
Aug 15 03:49:07 7 sSMTP[5241]: Creating SSL connection to host
Aug 15 03:49:07 7 sSMTP[5241]: SSL connection using ECDHE_RSA_AES_256_GCM_SHA384
Aug 15 03:49:07 7 cron[760]: sendmail: 450 Requested mail action not taken: mailbox unavailable
Aug 15 03:49:07 7 sSMTP[5241]: 450 Requested mail action not taken: mailbox unavailable
Aug 15 03:49:07 7 CRON[5236]: (andy) MAIL (mailed 63 bytes of output but got status 0x0001 from MTA#012)
Aug 15 03:49:46 7 gvfsd-metadata[1674]: g_udev_device_has_property: assertion 'G_UDEV_IS_DEVICE (device)' failed

这是 crontab 的一部分

  # m h  dom mon dow   command
   # Run my backup script at 10 a.m every day
   0 10 * * * /home/andy/bin/Backup_18_04.sh
  # Run my backup script at 8 p.m every day
  0 20 * * * /home/andy/bin/Backup_18_04.sh
  0 10 * * * /home/andy/bin/Send_Email.sh
  0 20 * * * /home/andy/bin/Send_Email.sh
  30 3 * * * /home/andy/bin/Send_Email.sh

这是我的脚本。

#!/bin/bash
# Ubuntu_Mate 18.04 LTS
#
# Send an email using a script
# Make sure there are several blank lines between Subject and the message.!!
CONTENT="Backup to Maxtor Drive has occured."
ssmtp -t << EOF
To: [email protected]
From: [email protected]
Subject: Backups to Maxtor Drive


$CONTENT
Cheers,
   Andy
EOF

怎么了?

答案1

它可能不够优雅,但是它在我的系统上确实有效。

#!/bin/bash
# Ubuntu_Mate 18.04 LTS
# 
# Backup sounds
cd /usr/share/sounds/My_Sounds/
echo yyy | sudo -S zip -u My_Sounds.zip *.mp3 *.wav
sudo zip -u My_Sounds.zip *.mp3 *.wav
# Send me email of the backup

CONTENT="Backup to Maxtor Drive has occured."
echo "Sending email."
/usr/sbin/ssmtp -t << EOF
To: [email protected]
From: [email protected]
Subject: Backups to Maxtor Drive


$CONTENT
Cheers,
   Andy
EOF

相关内容