Solved Some mail has no content

I use mail/ssmtp with mail via cron to send the output of some scripts to my email. I use a google email to send them to my main email address. Sometimes the email body will say "This message has no content". Here's an example from cron of a script where the email says this.

smartctl -a /dev/ada2 | mail -s "smart info for ada2" [I]email_address[/I]

I want to say that it has something to do with the size of the email being sent. Other commands such as:
sockstat -4l | mail -s "sockstat info" [I]email_address [/I]
This works fine.
 
Last edited by a moderator:
What happens whe you run the first example manually? Does it send a meaningful message?
It looks that in case when the first command fails (for any reason) it sends an empty message, e.g.:
Code:
$ smartctl -a /dev/ada2 | mail -s "smart info for ada2" sm@ara-ler.com
bash: smartctl: command not found
Null message body; hope that's ok
 
What happens whe you run the first example manually? Does it send a meaningful message?
It looks that in case when the first command fails (for any reason) it sends an empty message, e.g.:
Code:
$ smartctl -a /dev/ada2 | mail -s "smart info for ada2" sm@ara-ler.com
bash: smartctl: command not found
Null message body; hope that's ok
I do have sysutils/smartmontools installed. The command runs fine and the email is sent properly when not run in a cron job.
 
Last edited by a moderator:
Well, cron(8) doesn't have $PATH set, you should either set it in your script or use the full path to your program.
I'm confused, what does any of this have to do with $PATH? Everything runs fine apart from emails having no content in their body.
 
I think aragats is right. I only extent his answer. If a program is not within the path the cron(8) script does not find it. In general if you want start a program only the path is searched to find it. otherwise you have to specify the full path. In scripts this is safe to be independent of any path. Additionally you start the program you want and not an alias or something which has been copied to the path somehow. Regarding to you programs see the path as below.
Code:
% whereis smartctl
smartctl: /usr/local/sbin/smartctl /usr/local/man/man8/smartctl.8.gz
% whereis sockstat
sockstat: /usr/bin/sockstat /usr/share/man/en.UTF-8/man1/sockstat.1.gz /usr/src/usr.bin/sockstat
/usr/bin/ is likely to be within the default path of cron(8). It seems to be not the case for /usr/local/bin. Just make it a habbit to put the full path as /usr/local/bin/smartctl in your scripts. Then you can forget about the path issues. I also forgot that myself before aragats post above :rolleyes:.
 
I think aragats is right. I only extent his answer. If a program is not within the path the cron(8) script does not find it. In general if you want start a program only the path is searched to find it. otherwise you have to specify the full path. In scripts this is safe to be independent of any path. Additionally you start the program you want and not an alias or something which has been copied to the path somehow. Regarding to you programs see the path as below.
Code:
% whereis smartctl
smartctl: /usr/local/sbin/smartctl /usr/local/man/man8/smartctl.8.gz
% whereis sockstat
sockstat: /usr/bin/sockstat /usr/share/man/en.UTF-8/man1/sockstat.1.gz /usr/src/usr.bin/sockstat
/usr/bin/ is likely to be within the default path of cron(8). It seems to be not the case for /usr/local/bin. Just make it a habbit to put the full path as /usr/local/bin/smartctl in your scripts. Then you can forget about the path issues. I also forgot that myself before aragats post above :rolleyes:.
Where are you two getting that I have path issues?
 
Dear Zack,
please do not misunderstand me. The issue is related to cron(8) compared to the normal path. I have the similar behaviour here. It is not specific to your system. I did a short test to demonstrate that. The normal path can be retrieved as
Code:
% set | grep path
path   (/sbin /bin /usr/sbin /usr/bin /usr/games /usr/local/sbin /usr/local/bin /usr/home/chris/bin)
I changed my crontab to send me the path available by cron(8) by crontab -e and appending the line
Code:
*/1    *       *       *       *       set| mail -s "path" chris
which sends me a mail about the environment including the path once per minute. The path related line of the received mail is
Code:
PATH=/usr/bin:/bin
/usr/local/bin is not in. Therefore smartctl could not be found. /usr/local/bin/smartctl should be found because the full path is specified.
 
Nono I'm not arguing. I'm genuinely confused about how cron works now.

When a script is executed by cron by setting it in crontab -e, isn't it run as the user, or is it run as cron? I'm setting the script in cron, not the command.
 
Nono I'm not arguing. I'm genuinely confused about how cron works now.

Cron executes processes as a particular user: either the user to whom the crontab belongs, or the user specified in the cron job in the global /etc/crontab. It does this without a full or simulated login, so the environment for the user is never actually initialized and used by cron. So environment variables like $PATH need to be manually entered into the crontab. If you were to add the $PATH listing from your shell configuration to your crontab, you'd be able to execute cron jobs without absolute paths.
 
Something we all find or found out at some point in time ;-)

Cron and the immutable attribute set and encountering a file you cannot delete (and having no clue about the existence of said attribute hehe).. both got me raging for sure back in the day hehe
 
Back
Top