Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 来自CRON的AWS SES sendmail失败_Bash_Amazon Web Services_Cron_Amazon Ses - Fatal编程技术网

Bash 来自CRON的AWS SES sendmail失败

Bash 来自CRON的AWS SES sendmail失败,bash,amazon-web-services,cron,amazon-ses,Bash,Amazon Web Services,Cron,Amazon Ses,使用我配置的SES允许它从验证的电子邮件地址发送电子邮件。我能够使用已验证的电子邮件地址从命令行成功发送电子邮件: sudo /usr/sbin/sendmail -f from@example.com to@example.com < file_to_send.txt 问题 我设置了一个CRON作业,并将其设置为每5分钟运行一次以进行测试(脚本设计为在生产开始后每天运行一次): bash脚本复制并正确附加daily.txt文件,但不发送电子邮件。电子邮件假脱机中没有跳转或任何其他错误

使用我配置的SES允许它从验证的电子邮件地址发送电子邮件。我能够使用已验证的电子邮件地址从命令行成功发送电子邮件:

sudo /usr/sbin/sendmail -f from@example.com to@example.com < file_to_send.txt
问题

我设置了一个CRON作业,并将其设置为每5分钟运行一次以进行测试(脚本设计为在生产开始后每天运行一次):

bash脚本复制并正确附加daily.txt文件,但不发送电子邮件。电子邮件假脱机中没有跳转或任何其他错误

今天我花了大部分时间搜索答案,很多搜索结果都是死路一条,几乎没有关于使用CRON通过AWS SES发送电子邮件的信息

如何解决这个问题?

cron的一个“问题”是缺少环境变量(出于明显的安全原因)。你可能错过了路和家。您可以直接在脚本中或在crontab文件中定义它们

添加路径=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/us‌​r/bin在调用sendmail脚本之前,请将其发送到crontab,它应该可以工作

#!/bin/bash  
#Adding the path                                                                                                                                                                                     
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/us‌​r/bin

# copy the cw file                                                                                                                                                                       
cp /var/log/cwr.log /cwr_analysis/cwr.log                                                                                                          

# append the cw info to the subject file                                                                                                                                                 
cat /cwr_analysis/subject.txt /cwr_analysis/cwr.log  > /cwr_analysis/daily.txt                                                                                                    

# send the mail                                                                                                                                                                                   
/usr/sbin/sendmail -f from@example.com to@example.com < /cwr_analysis/daily.txt 
#/bin/bash
#添加路径
路径=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/us‌​回收箱
#复制cw文件
cp/var/log/cwr.log/cwr\u analysis/cwr.log
#将cw信息附加到主题文件
cat/cwr\u analysis/subject.txt/cwr\u analysis/cwr.log>/cwr\u analysis/daily.txt
#寄信
/usr/sbin/sendmail-ffrom@example.com to@example.com
您必须进行测试,直到脚本要求定义所有必要的变量。

cron的一个“问题”是缺少环境变量(出于明显的安全原因)。你可能错过了路和家。您可以直接在脚本中或在crontab文件中定义它们

添加路径=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/us‌​r/bin
在调用sendmail脚本之前,请将其发送到crontab,它应该可以工作

#!/bin/bash  
#Adding the path                                                                                                                                                                                     
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/us‌​r/bin

# copy the cw file                                                                                                                                                                       
cp /var/log/cwr.log /cwr_analysis/cwr.log                                                                                                          

# append the cw info to the subject file                                                                                                                                                 
cat /cwr_analysis/subject.txt /cwr_analysis/cwr.log  > /cwr_analysis/daily.txt                                                                                                    

# send the mail                                                                                                                                                                                   
/usr/sbin/sendmail -f from@example.com to@example.com < /cwr_analysis/daily.txt 
#/bin/bash
#添加路径
路径=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/us‌​回收箱
#复制cw文件
cp/var/log/cwr.log/cwr\u analysis/cwr.log
#将cw信息附加到主题文件
cat/cwr\u analysis/subject.txt/cwr\u analysis/cwr.log>/cwr\u analysis/daily.txt
#寄信
/usr/sbin/sendmail-ffrom@example.com to@example.com

您必须进行测试,直到脚本要求定义所有必要的变量。

cron作业是否添加为
root
user?是@helloV,cron用于root用户。您尝试过吗?cron作业是作为root用户添加的吗?是@helloV,cron是为root用户添加的。您尝试过这个吗?CRON正在工作,只是没有发送电子邮件。我的意思是添加路径可以帮助它找到运行sendmail命令所需的env变量。添加哪个路径?sendmail的路径在脚本中定义得非常清楚。请尝试向CRON添加
path=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
。CRON正在工作,它只是不发送电子邮件。我的意思是,添加路径将帮助它找到运行sendmail命令所需的环境变量。添加哪个路径?脚本中非常清楚地定义了sendmail的路径。请尝试将
path=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
添加到cron
*/5 * * * * /home/ec2-user/cwr_email.sh
#!/bin/bash  
#Adding the path                                                                                                                                                                                     
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/us‌​r/bin

# copy the cw file                                                                                                                                                                       
cp /var/log/cwr.log /cwr_analysis/cwr.log                                                                                                          

# append the cw info to the subject file                                                                                                                                                 
cat /cwr_analysis/subject.txt /cwr_analysis/cwr.log  > /cwr_analysis/daily.txt                                                                                                    

# send the mail                                                                                                                                                                                   
/usr/sbin/sendmail -f from@example.com to@example.com < /cwr_analysis/daily.txt