LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-29-2021, 05:26 AM   #1
littlebigman
Member
 
Registered: Aug 2008
Location: France
Posts: 660

Rep: Reputation: 35
Question Sending email without MTA?


Hello,

I use a cheap Debian computer as NAS to back up important files daily over the LAN.

I'd like to add a cron job so that the NSA checks disk usage, and sends an email the day the disk is 80% full.

Is there a way to send an email without setting up a whole MTA server (sendmail, Postfix, etc.)?

Thank you.

Code:
nas@debian:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       885G  395G  454G  47% /
 
Old 09-29-2021, 08:49 AM   #2
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS, Manjaro
Posts: 5,767

Rep: Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765
It is possible, so long as it is possible to access a mail server directly. I have done it, by hand, using telnet, so it can be done. Certainly it should therefor be possible to code the process. Issues will come in if the mail server in question uses some of the new encryption and security features, because those cannot easily be coded or scripted.

Possible does not mean smart. The smarter option is to install and configure a minimal MTA set up to use your mail server as a SMARTHOST. MSMTP and EXIM are reasonable options, but there are others. That way proper logging and handling outbound email is easier and you can use standard tools instead of reinventing the horse.
 
Old 09-29-2021, 09:36 AM   #3
littlebigman
Member
 
Registered: Aug 2008
Location: France
Posts: 660

Original Poster
Rep: Reputation: 35
Thank you.

I'll experiment, and see if I can send the email either directly to the target server, or through my ISP's SMTP server.
 
Old 09-29-2021, 01:27 PM   #4
descendant_command
Senior Member
 
Registered: Mar 2012
Posts: 1,876

Rep: Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643
Yes, there are some very small, basic MTA's for just this reason.

ssmtp, msmtp, esmtp are examples.
 
Old 09-29-2021, 01:50 PM   #5
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS, Manjaro
Posts: 5,767

Rep: Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765
Quote:
Originally Posted by descendant_command View Post
Yes, there are some very small, basic MTA's for just this reason.

ssmtp, msmtp, esmtp are examples.
I liked SSMTP, but I do not think it is still under development and may not work on some recent distro releases. There are a lot of MTA options.
 
Old 09-29-2021, 02:47 PM   #6
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,678

Rep: Reputation: Disabled
Well, I'm still using SSMTP on CentOS 8 as it is packaged for Fedora and can be easily rebuilt from Fedora sources.

For a similar setting on Ubuntu 20.04 LTS, I prefer dma.

Last edited by shruggy; 09-29-2021 at 02:49 PM.
 
Old 11-07-2021, 03:12 PM   #7
littlebigman
Member
 
Registered: Aug 2008
Location: France
Posts: 660

Original Poster
Rep: Reputation: 35
For some reason, cron doesn't send the email, while the script works OK if run manually:

Code:
~# crontab -l
50 11 * * Sun /root/show.free.disk.space.bash

~# ll /root/show.free.disk.space.bash
-rwxr-xr-x 1 root 166 Oct  4 11:45 /root/show.free.disk.space.bash*

~# cat /root/show.free.disk.space.bash
#!/bin/bash

CURRENT=$(df --output=pcent / | sed 1d)
printf 'To: me@isp.com\nSubject: Disk space\n\nRoot partition %s full.'  "$CURRENT" | ssmtp me@isp.com
Is it a security reason?
 
Old 11-07-2021, 03:51 PM   #8
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,678

Rep: Reputation: Disabled
A couple of wild guesses.

1) From the crontab(5) man page:
Quote:
cron requires that each entry in a crontab end in a newline character. If the last entry in a crontab is missing a newline (i.e. terminated by EOF), cron will consider the crontab (at least partially) broken. A warning will be written to syslog.
2) Try sun or 0 instead of Sun. It shouldn't matter, but there're different implementations of cron: Vixie cron, cronie, etc. POSIX only mandates numbers as days of week.
 
Old 11-08-2021, 05:27 AM   #9
littlebigman
Member
 
Registered: Aug 2008
Location: France
Posts: 660

Original Poster
Rep: Reputation: 35
Thanks for the tips.

The last line did end with a carriage return, so that wasn't it.

I should have checked /var/log/sys

Code:
Nov  8 12:25:01 debian CRON[2845]: (root) CMD (/root/show.free.disk.space.bash)
Nov  8 12:25:01 debian cron[2852]: sendmail: 550 5.7.1 <root@isp.com>: Sender address rejected: you are not root@isp.com
Nov  8 12:25:01 debian sSMTP[2852]: 550 5.7.1 <root@isp.com>: Sender address rejected: you are not root@isp.com
Nov  8 12:25:01 debian CRON[2844]: (root) MAIL (mailed 66 bytes of output but got status 0x0001 from MTA#012)
Heres's how I configured ssmtp:
Code:
~# cat /etc/ssmtp/ssmtp.conf
root=postmaster
mailhub=smtp.isp.com
hostname=isp.com
FromLineOverride=YES

~# cat /etc/ssmtp/revaliases
root:me@isp.com:smtp.isp.com
Changing ownership of the script makes no difference:
Code:
chown fred.fred show.free.disk.space.bash

Last edited by littlebigman; 11-08-2021 at 05:39 AM.
 
Old 11-08-2021, 06:08 AM   #10
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,678

Rep: Reputation: Disabled
Quote:
Originally Posted by littlebigman View Post
Changing ownership of the script makes no difference:
Code:
chown fred.fred show.free.disk.space.bash
No, this is wrong. You are executing a cronjob for root. cron checks that root owns the file and will refuse to open it otherwise.

Rather, try to explicitly specify the From: name either in the body of the message or on the ssmtp command line with -fname.
 
Old 11-08-2021, 07:10 AM   #11
littlebigman
Member
 
Registered: Aug 2008
Location: France
Posts: 660

Original Poster
Rep: Reputation: 35
I tried those, one after the other, still NOK:
Code:
printf 'From: me@isp.com\nTo: me@isp.com\nSubject: Disk space\n\nRoot partition %s full.'  "$CURRENT" | ssmtp me@isp.com

printf 'From: me@isp.com\nTo: me@isp.com\nSubject: Disk space\n\nRoot partition %s full.'  "$CURRENT" | ssmtp -f"me@isp.com" me@isp.com
Output:
Code:
cron[266]: sendmail: 550 5.7.1 <root@isp.com>: Sender address rejected: you are not root@isp.com
sSMTP[24771]: 550 5.7.1 <root@isp.com>: Sender address rejected: you are not root@isp.com
CRON[24759]: (root) MAIL (mailed 61 bytes of output but got status 0x0001 from MTA#012)
Since ssmtp is deadware since 2013, I'll experiment with msmtp.
 
Old 11-08-2021, 07:12 AM   #12
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,678

Rep: Reputation: Disabled
Then run it not as a root, but as a regular user cronjob.
 
Old 11-08-2021, 08:16 AM   #13
littlebigman
Member
 
Registered: Aug 2008
Location: France
Posts: 660

Original Poster
Rep: Reputation: 35
It doesn't work either: For some reason, ssmtp is invisible to a non-root user:
Code:
fred@debian:~$ ./test.bash: line 9: ssmtp: command not found
fred@debian:~$ which ssmtp
fred@debian:~$
Besides, I get the same error in syslog even after creating /etc/cron.d/cron.allow to include root + fred, and adding a job as "fred":
Code:
CRON[25475]: (fred) CMD (test.bash)
cron[266]: sendmail: 550 5.7.1 <root@isp.com>: Sender address rejected: you are not root@isp.com
sSMTP[25476]: 550 5.7.1 <root@isp.com>: Sender address rejected: you are not root@isp.com
 
Old 11-08-2021, 08:22 AM   #14
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS, Manjaro
Posts: 5,767

Rep: Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765
Have you considered modifying the script to use sudo or doas for the parts that need to run as root, but having it scheduled, run, and send mail under your personal account?

This presumes that your personal account has no problem sending email.
 
Old 11-08-2021, 08:44 AM   #15
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,678

Rep: Reputation: Disabled
Why explicitly run ssmtp from the script at all? If ssmtp is set up as your MTA, sending mails with mailx from the command line should also work.
 
  


Reply

Tags
cron



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Temporary MTA failure on relaying, From MTA() during fwd-connect (No greeting, dt: 1.005 s) kwickcut Ubuntu 2 02-15-2021 01:34 PM
error sending email via mutt/msmtp w/ cronjob (status 0x0001 from MTA#012) jorjor242 Linux - Software 21 04-17-2020 02:09 PM
email without local mta daemon running jag7720 Linux - Server 4 07-18-2012 06:38 PM
Sendmail is installed as default MTA. How do I switch to Postfix as MTA? virtualpal Linux - Newbie 5 05-11-2009 02:10 AM
MTA alternative or start MTA later? lomix Linux - Software 2 04-17-2008 08:07 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration