I have created a bash-script which does certain backup jobs and mails the results. Everything works fine when I call the script from the shell as user root. The shebang of the script is set correctly (#!/usr/bin/bash). The script is designed in a way to use absolute paths and not expect to be called from a specific directory.
However, when I call the script from the crontab-system from TrueNAS (also called as “root”), then the script fails in strange ways.
First, at the beginning it throws the message sudo: argv[7] mismatch, expected ". Secondly, there is a for-loop in the script (loops through a list). For some reason it only does the first two entries in the list, the rest is ignored, but the two entries it does several times.
In CORE this worked, in SCALE this failed. I corrected the shebang. For other things, I wouldn’t know what to correct.
A few things we can think of at first from the info you provided here are,
sudo in the script might not be necessary as you mentioned its running as root
if the loop seems to be doing 2 iterations, look for an exit call somewhere in the logic for some condition - may be you want to continue the loop than exiting the program
try calling the script with some kind of simple logging to a text file, to do a quick debug
hope this gives a starting point for your troubleshooting.
After more troubleshooting, I found that the errors I reported are actually all to be located in the email-send-script which I call in the end of the backup-script. The backup itself works fine. I’m currently troubleshooting this (I use TrueNAS API for this). Again, this works when called from shell, but not from crontab. Trying to fix this with Gemini. =)
Suggestion: Use sendemail.py as it works for many, and I use it in Multi-Report. Okay, it was originally designed for Multi-Report but was adapted to other uses.
When i was exploring sendemail alternative, i get triggered a lot by the native API… nor for the payload size limit and for the nested JSON structure need to send attacchments that was always rejected. And the error you mentioned in first post point remembered me this last case, if you want be sure just remove attacchments and if i’m correct mail should work
Or as Joe suggest , check my script and see if can meet your needs
Realize that in SCALE recently there was additional hardening which caused some grief for my script. So far all is working in SCALE through 25.10 (nightly) as of this posting. That could change if additional hardening causes problems as 25.10 is developed.
One additional note: the CRON command line may be your issue here. I have to use cd /mnt/pool/scripts && ./multi_report.sh in order to make it work. This will put you in the directory where the script resides and then run the script in a shell. If you haven’t tried this, give it a try.
Yes exactly, it’s a pain… I just tried your script and it worked out of the box. May I ask two questions about it?
While it worked out of the box, I found that it chooses automatically the from-email-address which is set in the TrueNAS-GUI (which is fine and which works for me). However, it would be nice being able to override it to a different email-address, using otherwise the same email-settings. I use “customized” from-addresses for different services so I can distinguish in the mailbox. They are all aliases from the same email-account.
I geht the error-message “>> Soft warning: something wrong with 1 or more attachments, check logs for more info >>”. If I enable debug-logging and check the log, I don’t see anything special, and attaching seemed to work? What does the error-message refer to?
2 totals file log
1 totals attachment
trying read mail.config
read mail.config successfully
Switching for the right provider
** SMTP Version **
parsing smtp config
switch from classic send and bulk email
mail hmtl provided
parsing html content
no file found, plain text/html output
start parsing headers
parsing data from config
using fromemail <redacted>
generate a message ID using 65279mail2
65279mail2 not a valid address, tryng on <redacted>
domain: <redacted>
uuid: 2025_03_30_21_00_35_168373bf3a7-c844-4d02-bc1c-0b8f32d3d74c
messageid: <2025_03_30_21_00_35_168373bf3a7-c844-4d02-bc1c-0b8f32d3d74c@<redacted>>
check for attachements...
attachments found
OK /mnt/DATA/shares/persistent/logs/backup.log
1 ok attachments
get hostname
hostname retrieved: <redacted>
tryng retrieving if more recipient are set
establing connection based on security level set on TN: TLS
entered TLS path
adding ehlo to the message
establing TLS connection
entering credentials
sending TLS email
Email Sent via SMTP
<< Email Sent >>
>> Soft warning: something wrong with 1 or more attachments, check logs for more info >>
yep, i totally understand what you mean: this has been one of firsts choices i made at beginning, so i don’t deny that Is most a personal choice to avoid issues when the script was intended to work just with multi report.
For example, gmail allow only confirmed alias, but the mail will be sent anyway; for SMTP user instead this can be reason of reject most of time; also i assume that with Outlook will be pretty the same (but honestly i don’t have made some test forcing another address yet, not being the standard behaviour).
So actually, there Is a way to override the sender name/address, but Is strictly related to the presence of the multi report config file, and work only with gmail, but i can totally considering that as a new feature for next release!
honestly, Is odd, i will check as i can if i have made a regression in the last release: watching your debug seems that the variable that should handle the ok attacchment value Is not well initialized, and will raise the warning. I will update you on this