无法以超级用户身份运行脚本,通过电子邮件向我发送结果。(返回:发送电子邮件:550 5.1.0 不是我们的客户)

无法以超级用户身份运行脚本,通过电子邮件向我发送结果。(返回:发送电子邮件:550 5.1.0 不是我们的客户)

我已经尝试调试这个问题两天了,但没有成功。这是我尝试运行的脚本:

#!/bin/bash
emailaddress='[email protected]'
output=`sudo rsync -av --delete /media/sync/1/backup /media/sync/2/`
echo $output|mail -s "backup_rsync.sh: backup_rsync run" $emailaddress;

当我以普通用户身份直接从命令行或作为 cron 作业运行它时,我可以获得所需的结果。这就是为什么我认为脚本本身没有任何问题。该脚本具有以下权限:

-rwxr--r-- 1 pi pi 190 Jan  4 08:52 scripts/backup_rsync.sh

问题是,当我尝试使用 sudo 运行相同的脚本(位于 /root 中的不同文件)或者甚至以 root 身份登录时,我得到以下结果:

发送邮件:550 5.1.0 不是我们的客户

这些是位于 /root 的脚本的权限:

-rwxr--r-- 1 root root 190 1 月 4 日 13:43 /root/backup_rsync.sh

我的操作系统是 RaspberryPi Model B+ 上的最新版本 Raspbian。我安装了 ssmtp heirloom-mailx 来处理电子邮件。我的 ssmtp.conf 文件如下:

#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
[email protected]

# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named mail.domain.com
mailhub=smtp.comcast.net:587

# Where will the mail seem to come from?
rewriteDomain=comcast.net

# The full hostname
hostname=raspberrypi

# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
FromLineOverride=YES

UseTLS=Yes
UseSTARTTLS=Yes

AuthUser=my_login
AuthPass=my_password

上面列出的“my_login”和“my_password”只是填充。在实际文件中,我插入了正确的信息,就像我说的,当我以普通用户身份发送电子邮件时,它可以正常工作。任何帮助都将不胜感激。如果需要更多信息,请告诉我。

编辑如下以获取更多信息

这些是我的 root crontab 中的行:

38 9 * * * /root/backup_rsync.sh >> /tmp/mylog 2>&1
38 9 * * * touch /tmp/my_cronjob_ran1

如您所见,我一直在尝试调试这个东西。它确实生成了“my_cronjob_ran1”文件,所以我知道根 crontab 正在运行。在“mylog”文件中,我收到了“send-mail: 550 5.1.0 Not our Customer”消息。

下面是我的用户 crontab 中的一行(产生所需结果的一行):

00 03 * * * /home/pi/scripts/backup_rsync.sh

最终编辑。我找到了问题所在。

我检查了 /var/log/syslog 并在尝试更多测试时看到了这些消息:

Jan  5 20:07:15 raspberrypi sSMTP[3507]: Creating SSL connection to host
Jan  5 20:07:16 raspberrypi sSMTP[3507]: SSL connection using RSA_AES_128_CBC_SHA1
Jan  5 20:07:17 raspberrypi sSMTP[3507]: Sent mail for [email protected] (221 2.0.0 resomta-ch2-04v.sys.comcast.net comcast closing connection) uid=1000 username=pi outbytes=494

Jan  5 20:07:31 raspberrypi sSMTP[3513]: Creating SSL connection to host
Jan  5 20:07:31 raspberrypi sSMTP[3513]: SSL connection using RSA_AES_128_CBC_SHA1
Jan  5 20:07:32 raspberrypi sSMTP[3513]: Sent mail for [email protected] (221 2.0.0 resomta-ch2-01v.sys.comcast.net comcast closing connection) uid=1000 username=pi outbytes=490

Jan  5 20:09:44 raspberrypi sSMTP[3532]: Creating SSL connection to host
Jan  5 20:09:45 raspberrypi sSMTP[3532]: SSL connection using RSA_AES_128_CBC_SHA1
Jan  5 20:09:46 raspberrypi sSMTP[3532]: 550 5.1.0 Not our Customer

前 6 行是我从我的登录名 (pi) 发送消息。最后三行是我再次尝试从 (root) 发送电子邮件。这告诉我它正在连接到 Comcast,我收到的错误消息来自他们。然后我在 Windows 计算机上打开 Thunderbird 并尝试向[电子邮件保护](来自我的常用电子邮件地址)。然后我在 Thunderbird 中收到此错误:

发送邮件时出错。邮件服务器响应:5.1.1 不是我们的客户。请检查邮件收件人[电子邮件保护]然后再试一次。

因此确认了该消息来自 Comcast。我解决问题的方法是将 ssmtp.conf 文件中的此行 (rewriteDomain=comcast.net) 更改为此行 (rewriteDomain=gmail.com)。现在一切正常。我认为这是因为 Comcast 无法知道它是否是有效的电子邮件地址,只能知道 gmail.com 是有效的域。

感谢所有看过这篇文章并试图提供帮助的人。如果我的推理有误,或者有人有任何补充,请告诉我。

相关内容