Mail - help with setting up cron job to send email daily

NethServer Version: 7.9.2009

Hello Forum,

Looking for some help/direction on how I can setup a daily email from my Nethserver. I’m thinking of a corn job to do what I need. Anyone done this before and if so can you provide me some instructions on how I can set this up?

Thank you.

Hi @greavette

As you’re talking about NS7, @stephdl made a nice module here:

This gives you a nice GUI to set the times and jobs (tasks) you want to set.

This can be a simple command (example: cp path_to_file path_to_target.), or a script.
For scripts, I’ld suggest using a static folder (eg: /etc/scripts, I use /etc/Jobs for legacy reasons…)

Here a real life screenshot:

(I generally use / prefer the advanced settings, the same syntax as “cron” itself uses… But here is the simple view:

As you can see from the screenshot, I use this to run additional backup jobs, trigger a backup to be sent offsite, or grab the configuration of my OPNsense firewalls and store these somewhere…

A few “Gotchas”:

  • Anything put in crontab needs the full path for any binary, paths are not expanded to include the system “path” variable. Example: “poweroff” as a command will NOT work: you need to use /usr/sbin/poweroff…
  • If you use a script, that script must be set executable by the user (usually root!). Here, paths do work.
[root@wpd-nethserver Jobs]# ls -la
total 68
drwxr-xr-x    2 root root    243 Oct 17  2022 .
drwxr-xr-x. 179 root root  12288 Apr  5 01:08 ..
-rwsr-x---    1 root root   3638 Oct  2  2022
-rwsr-x---    1 root root   4474 Oct 23  2021
-rwsr-x---    1 root root   4693 Nov 28  2018
-rwsr-x---    1 root root   4513 Dec 26  2018
-rwsr-x---    1 1024 users  3929 Oct 17  2022
-rwsr-x---    1 root root   4476 Oct 23  2021
-rwxrwx---    1 root root    973 Apr  2  2021
-rwxrwx---    1 root root    980 Apr  2  2021
-rwxrwx---    1 root root    979 Apr  2  2021`Preformatted text`

I hope these instructions point you in the right direction, and are understandable as such…
If you need pointers to the actual script, drop me a PM…

My 2 cents

To get the full path of a binary, use:

whereis BINARY


whereis poweroff

(In /usr/share/man are where the UN*X “man” pages are to be found…)


Here is an example of the mail command sending a mail to name@domain.tld

/usr/bin/echo "This is a testmail" | /usr/bin/mail -s "Subject" name@domain.tld


Hello @Andy_Wismer and @mrmarkuz ,

Amazing support and answers here…thanks very much for you input!

Andy, this module by @stephdl is just what I needed! Thank you.
Markus, this instruction you gave to send an email. I’ve tried adding this to module Andy showed me. Doesn’t appear I’m doing something right here. I’d like to have this email sent daily at 6 am daily (7 days a week). I’ve created the following job in Crontab Manager but I’m getting an error that says:

The validation has been failed: This command line is not allowed : [ “\” ]

Secondly, the reason I’m looking to implement this test is because I’ve had some strange issues with email suddenly. We use a group list of people to send an email to daily. This week we started receiving an error in the Email > Queue related to ‘Too many recipients’. An example of the full details of the deferred email is:

host[] said: 452 4.5.3 Too many recipients (AS780090) [YT2PEPF000001CF.CANPRD01.PROD.OUTLOOK.COM 2024-04-17T14:23:06.475Z 08DC54043411C1B3] (in reply to RCPT TO command)

Thank you!

You need to put all your commands into a file (script), store that somewhere accessible (I use /etc/Jobs, but eg /etc/scripts would be fine.).

Then put the full path to your script there as command. ( eg /etc/scripts/ ).

The script file needs to be executable for root!

Using advanced options in Cron, you need 5 tokens in the “Time of the job” field.
eg: "0 6 * * * "

That would work!

My 2 cents

1 Like