[LINUX] The story that sendmail that can be executed in the terminal did not work with cron

This is a memorandum of what to do when a shell script including sendmail on Linux works with terminal commands but does not work with cron.

After writing the shell in the following format, I wrote cron to run it on time. Then, it worked normally on the command and the mail was sent, but the mail was not sent even at the scheduled time written in cron.

mail.sh


#!/bin/sh
{
echo "From: <****@gmail.com> "
echo "To: <****@gmail.com> "
echo "Subject:title"
echo "Content-Type: text/plain;charset='UTF-8'"
echo "Content-Transfer-Encoding: base64"
}| sendmail -i -t

So, I first suspected that there was a problem with cron, changed the file permission to chmod 777, and then checked the log, but cron seemed to work without problems.

$ tail /var/log/cron
Aug  7 14:20:01 ip-***-**-*-** CROND[17995]: (root) CMD (/home/***/mail.sh)

I was able to conclude that the problem was in sendmail, so I looked around and found that if I added / usr / sbin /, it worked fine and the mail was sent, and I was able to receive it in the junk mail folder on gmail.

mail.sh


#!/bin/sh
{
echo "From: <****@gmail.com> "
echo "To: <****@gmail.com> "
echo "Subject:title"
echo "Content-Type: text/plain;charset='UTF-8'"
echo "Content-Transfer-Encoding: base64"
}| /usr/sbin/sendmail -i -t

Recommended Posts

The story that sendmail that can be executed in the terminal did not work with cron
The story that yapf did not work in vscode
The story that `while queue` did not work in python
The story of debugging in the local environment because the compilation did not work with Read the Docs
I bought and analyzed the year-end jumbo lottery with Python that can be executed in Colaboratory
Results that did not get caught in the search with this word
The story that fits in with pip installation
[Python] I examined the practice of asynchronous processing that can be executed in parallel with the main thread (multiprocessing, asyncio).
Goroutine (parallel control) that can be used in the field
I investigated the pretreatment that can be done with PyCaret
The story of exclude / include that Serverless Framework beginners misunderstood (did not understand) in beginner Pythonista
Make a Spinbox that can be displayed in Binary with Tkinter
A timer (ticker) that can be used in the field (can be used anywhere)
The story of the release work of the application that Google does not tell
A story that didn't work when I tried to log in with the Python requests module
Make a Spinbox that can be displayed in HEX with Tkinter
About the case that the speaker did not make sound in Ubuntu LTS 20.04
Mathematical optimization that can be used for free work with Python + PuLP
I made a simple timer that can be started from the terminal
A story that heroku that can be done in 5 minutes actually took 3 days
A story that did not end with exit when turning while with pipe input
I tried to predict the horses that will be in the top 3 with LightGBM
Since python is read as "Pichon", it can be executed with "Pichon" (it is a story)
The story that 5GHz band access point could not be created on Ubuntu
File types that can be used with Go
Functions that can be used in for statements
Building Sphinx that can be written in Markdown
List packages that can be updated with pip
PyQtGraph may not be available in the interpreter.
[systemd] How to deal with the problem that fancontrol does not work after suspending
Morphological analysis and tfidf (with test code) that can be done in about 1 minute
Solved the problem that the image was not displayed in ROMol when loaded with PandasTools.LoadSDF.
In Python3.8 and later, the inverse mod can be calculated with the built-in function pow.
File sharing server made with Raspberry Pi that can be used for remote work
When writing to a csv file with python, a story that I made a mistake and did not meet the delivery date
A story that I did not know how to load a mixin when making a front with the django app [Beginners learn python with a reference book in one hand]
Basic algorithms that can be used in competition pros
Japanese can be used with Python in Docker environment
Color list that can be set with tkinter (memorial)
Python knowledge notes that can be used with AtCoder
A story that struggled with the common set HTTP_PROXY = ~
ANTs image registration that can be used in 5 minutes
The story that Japanese output was confused with Django
Work memo that I tried i18n with Flask app
Limits that can be analyzed at once with MeCab
List the classes that can be referenced by ObjCClass
[Django] Field names, user registration, and login methods that can be used in the User model
How to display hover text and text that can be executed by clicking with Minecraft plugin
Dealing with the error that HTTP fetch error occurs in gpg and the key cannot be obtained
[VLC] How to deal with the problem that it is not in the foreground during playback