I have been trying to debug this for 2 days now, without success. This is the script I'm trying to run:
#!/bin/bash firstname.lastname@example.org' output=`sudo rsync -av --delete /media/sync/1/backup /media/sync/2/` echo $output|mail -s "backup_rsync.sh: backup_rsync run" $emailaddress;
I can get the desired results when I run it, directly from the command line or as a cron job, as a regular user. That's why I don't think there is anything wrong with the script itself. The script has the following permissions:
-rwxr--r-- 1 pi pi 190 Jan 4 08:52 scripts/backup_rsync.sh
The problem is when I try to run the same script (different file located in /root) using sudo, or even logged in as root, I get the following results:
send-mail: 550 5.1.0 Not our Customer
These are the permissions for the script located in /root:
-rwxr--r-- 1 root root 190 Jan 4 13:43 /root/backup_rsync.sh
My OS is the latest version Raspbian on my RaspberryPi Model B+. I have installed ssmtp heirloom-mailx to handle email. My ssmtp.conf file is as follows:
# # Config file for sSMTP sendmail # # The person who gets all mail for userids < 1000 # Make this empty to disable rewriting. email@example.com # 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
Where "my_login" and "my_password" are listed above are just fillers. In the real file I have the correct information inserted and, like I said, it works when I email as a regular user. Any help would be appreciated. Let me know if more information is needed.
Edited below for more information
These are the lines from my root crontab:
38 9 * * * /root/backup_rsync.sh >> /tmp/mylog 2>&1 38 9 * * * touch /tmp/my_cronjob_ran1
As you can see, I've been trying to debug this thing. It does produce the "my_cronjob_ran1" file, so I know the root crontab is running. In the "mylog" file is where I get the "send-mail: 550 5.1.0 Not our Customer" message.
Here is the line from my user crontab (the one that is producing the desired results):
00 03 * * * /home/pi/scripts/backup_rsync.sh
Final Edit. I figured out the problem.
I checked the /var/log/syslog and saw these messages when I tried some more testing:
Jan 5 20:07:15 raspberrypi sSMTP: Creating SSL connection to host Jan 5 20:07:16 raspberrypi sSMTP: SSL connection using RSA_AES_128_CBC_SHA1 Jan 5 20:07:17 raspberrypi sSMTP: Sent mail for firstname.lastname@example.org (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: Creating SSL connection to host Jan 5 20:07:31 raspberrypi sSMTP: SSL connection using RSA_AES_128_CBC_SHA1 Jan 5 20:07:32 raspberrypi sSMTP: Sent mail for email@example.com (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: Creating SSL connection to host Jan 5 20:09:45 raspberrypi sSMTP: SSL connection using RSA_AES_128_CBC_SHA1 Jan 5 20:09:46 raspberrypi sSMTP: 550 5.1.0 Not our Customer
The first 6 lines were me sending a message from my login (pi). The last three lines were me trying to send an email from (root) again. This told me that it was making a connection to Comcast and the error message I was getting was from them. I then opened up Thunderbird on my Windows machine and tried to send a message to firstname.lastname@example.org (from my regular email address). I then got this error in Thunderbird:
An error occurred while sending mail. The mail server responded: 5.1.1 Not our Customer. Please check the message recipient email@example.com and try again.
So that confirmed the message was coming from Comcast. What I did to fix the problem was I changed this line (rewriteDomain=comcast.net) in my ssmtp.conf file to this (rewriteDomain=gmail.com). Now everything works as it should. I assume it is because Comcast has no way of knowing if it is a valid email address, only that gmail.com is a valid domain.
Thank you to everyone who viewed this and tried to help. If I'm off on my reasoning, or if anyone has anything to add, please let me know.