Script and Cronjob Help

Lubuntu 24.04 LTS Minimal (no snaps)
Either I’m reading the wrong stuff, reading stuff wrong, or I need to make some changes.
Most likely all of the above.
Please help me with this.

Using claws-mail to view emails from cron.
I want both stdout and stderr.
So far nothing yet, even after changing the minute, hour and target directory in the crontab entry.

The script needs sudo
Owner is wyatt
Permissions are set to

chmod a+x

sudo crontab entry is

43 11 * * * /home/wyatt/Desktop/System-Reports.sh 2>/home/wyatt/mail

The script currently is on the Desktop and looks like this…

#!/bin/bash

# Create the directory where system reports go into
   mkdir /home/wyatt/Desktop/System-Reports

   journalctl -p emerg -b > /home/wyatt/Desktop/System-Reports/Jctl_emerg.txt
   journalctl -p alert -b > /home/wyatt/Desktop/System-Reports/Jctl_alert.txt
   journalctl -p crit -b > /home/wyatt/Desktop/System-Reports/Jctl_crit.txt
   journalctl -p err -b > /home/wyatt/Desktop/System-Reports/Jctl_err.txt
   journalctl -p warning -b > /home/wyatt/Desktop/System-Reports/Jctl_warning.txt
   journalctl -p notice -b > /home/wyatt/Desktop/System-Reports/Jctl_notice.txt
   journalctl -p info -b > /home/wyatt/Desktop/System-Reports/Jctl_info.txt
   journalctl -p debug -b > /home/wyatt/Desktop/System-Reports/Jctl_debug.txt

# /home/wyatt/.xsession-errors

# Check and Review log files
   grep -Ei 'warn|error' /var/log/*g > /home/wyatt/Desktop/System-Reports/Log-Warnings-Errors.txt
   grep -Ei 'warn|error|emerg|alert|crit|noti|info|debug|fail' /var/log/*g > /home/wyatt/Desktop/System-Reports/Log-All.txt
   grep -Ei 'warn|error|emerg|alert|crit|noti|info|debug|fail' /var/log/dmesg > /home/wyatt/Desktop/System-Reports/DMesg-Reports.txt

# Check and Review dmesg log
   tac /var/log/dmesg > /home/wyatt/Desktop/System-Reports/DMesg-Logfile.txt

First check if cron service is active and running:
sudo systemctl status cron.service

Also, if you run that script from a root terminal session and using the exact command from the crontab, does it work as expected?

Because the 2>/home/wyatt/mail … as you have not put any extension to mail (tipically .log or .txt) I guess you may be using a folder mail instead of a file into a folder and it doesn’t work.

1 Like

maildir is special directory and maybe require MTA, but also could be assemble(d) and deliverd. User then could fetch them from server the way he choose, including TB or other mail agent or even remote. But that is vulnerable to admin work or additional needed work according needs if this way is choosed.

Otherwise maybe some env is required from cron, it is system job or systemd job :slight_smile:

Would the “export to System-Reports” Desktop directory specified within the script over-ride the “export to” specified in the crontab entry?

Should I specify a filename.ext to export to /var/spool/mail?

Should I make a directory within /var/spool/mail and specify that directory and filename in the crontab entry?

[QUOTE]First check if cron service is active and running:

   sudo systemctl status cron.service

And terminal says…

● cron.service - Regular background program processing daemon Loaded: loaded (/usr/lib/systemd/system/cron.service; enabled; preset: enabled) Active: active (running) since Fri 2025-01-31 13:03:34 EST; 10h ago Docs: man:cron(8) Main PID: 700 (cron) Tasks: 1 (limit: 9288) Memory: 3.7M (peak: 8.8M) CPU: 3.711s CGroup: /system.slice/cron.service └─700 /usr/sbin/cron -f -P
That “running since 10h ago” is from the time I last rebooted at 1:03pm before I went to get groceries and household needs for the month.

I’m not sure, let’s check that…

   sudo /home/wyatt/Desktop/System-Reports.sh 2>/home/wyatt/mail

I don’t know if I did this correctly as a “root terminal session” (not exactly sure how to do that)
but here’s what terminal says…

bash: /home/wyatt/mail: Permission denied

I can run the script manually and that works but that’s how I been getting the reports before. However, I need cron to do this for me to free up some time for me to actually rectify the errors and warnings and be able to actually use the pc rather than trying to constantly maintain it.

The “/home/wyatt/mail” is from within claws-mail.
I’ve checked that and yes it is a directory, and now since that is mentioned, I wonder if that directory was created when I first opened claws-mail.
I read in one of the old forum threads that if a directory isn’t specified to send mail to…that /var/spool or /var/spool/mail will fill up with mail.

As far as I know, claws-mail supports MTA.
Hopefully that’s what is meant by mentioning that MTA may be required.
If not, please explain that.

Test if this works: change crontab to this:

MAILTO="username"
43 11 * * * /home/wyatt/Desktop/System-Reports.sh
MAILTO=""

It will sent the results of any cronjob to the mail of the user “username” (if it’s correctly assigned).
Then execute the command.
And finally leave email of the crontab in blank so you can put more crontab entries without sending results to any mail.

The email folder usually is /var/spool/mail/“username” but it depends of some factors…

[QUOTE]Test if this works: change crontab to this:

MAILTO="username" 43 11 * * * /home/wyatt/Desktop/System-Reports.sh MAILTO=""
It will sent the results of any cronjob to the mail of the user “username” (if it’s correctly assigned).
Then execute the command.
And finally leave email of the crontab in blank so you can put more crontab entries without sending results to any mail.

The email folder usually is /var/spool/mail/“username” but it depends of some factors…[/QUOTE]

I’m uncertain if you’d seen the questions in my last post…

[QUOTE]Would the “export to System-Reports” Desktop directory specified within the script over-ride the “export to” specified in the crontab entry?

Should I specify a filename.ext to export to /var/spool/mail?

Should I make a directory within /var/spool/mail and specify that directory and filename in the crontab entry?[/QUOTE]

The command below is how I ran the script manually.

   sudo /home/wyatt/Desktop/System-Reports.sh

The reports would be exported to…

home/wyatt/Desktop/System-Reports

No exports to /var/spool/mail by cron.
Should /var/spool/mail/wyatt be automatically created?
or do I need to run…

   sudo /usr/bin/mkdir /var/spool/mail/wyatt

The fact is that I can’t answers most of your questions because I’m not using local mail in my Ubuntu machines, I just sent the emails from the my machines to my gmail account to saw them in my mobile. It’s something fairly easy, by the way.

I can help you to setup that kind of setup, you only need a gmail account. But I don’t know how to setup a local mail, I believe is not as easy as putting a text file in a folder and it works.

I can’t access my gmail account.
Do you know if it will work with a yahoo mail account and is your gmail account directed through a gmail client installed on your phone?
I have an online yahoo mail account.
We can try to set it up to send to my @yahoo.com account.

The gmail account is only used to sent the emails but you can sent emails to any account (yahoo, hotmail, etc…). So you just need a gmail account to sent emails but you can sent them to your yahoo email without problems.

I don’t know if a yahoo account should work but we can try…

Install nullmailer (is an MTA forwarder).
sudo apt install nullmailer

Edit these nullmailer configuration files (create if don’t exists):

/etc/nullmailer/allmailfrom will contain your yahoo mail (xxxxxxx@yahoo.com)

/etc/nullmailer/adminaddr will contain your yahoo mail (xxxxxxx@yahoo.com)

/etc/nullmailer/defaultdomain will contain the hostname of your machine

/etc/nullmailer/remotes will contain the comand to sent the emails using yahoo: the problem is that I don’t know if yahoo allow to do this. Try putting:
smtp.mail.yahoo.com smtp --auth-login --port=587 --starttls --user=xxxxxxxxxx@yahoo.com --pass=xxxxxxxxxxxxx

And sent yourself a test mail:
printf "Subject: TEST EMAIL\n\nThis is a test email" | sendmail -F xxxxxxxx@yahoo.com -v xxxxxxx@yahoo.com

ok, thank you
I will try this after putting my better half to bed and report back here as soon as I see result either good or bad.
Should be seeing results before 4:30 Eastern time.
Is that ok?

I can’t guarantee a concrete time but I’ll check as soon as possible.

How do I find the hostname of my machine or how do I set a variable to designate my machines hostname?

Also, what goes into the crontab and what changes (if any) needs to be made in the script?

Use hostname command.

First we need to check if it works.

ok
and in your guide there’s “–pass=xxxxxxxxxxxxx”
what do those “x’s” change to?

To your yahoo account password.

ok
I’ll test in about half hour and post the results here.

With the x’s changed to the proper…

how exactly should the contents of this file be?
and…
Could the port number need to be changed to something else to match my machine or yahoo.com?
In /etc/nullmailer/remotes…I changed from this…

mail

to this…

[CODE]commented out with a '#'mail

smtp.mail.yahoo.com smtp --auth-login --port=587 --starttls --user=xxxxxxxxxxx@yahoo.com --pass=xxxxxxxxxxxxx[/CODE]

I tested different command’s…

   smtp.mail.yahoo.com smtp --auth-login --port=587 --starttls --user=xxxxxxxxxxx@yahoo.com --pass=xxxxxxxxxxxxx (yahoo password)
   sudo smtp.mail.yahoo.com smtp --auth-login --port=587 --starttls --user=xxxxxxxxxx@yahoo.com --pass=xxxxxxxxxxxxx
   sudo /usr/lib/smtp smtp.mail.yahoo.com --auth-login --port=587 --starttls --user=xxxxxxxxxx@yahoo.com --pass=xxxxxxxxxxxxx
   sudo /etc/nullmailer smtp.mail.yahoo.com --auth-login --port=587 --starttls --user=xxxxxxxxxx@yahoo.com --pass=xxxxxxxxxxxxx

and terminal says…and still no mail to my yahoo account.

   sudo smtp.mail.yahoo.com smtp --auth-login --port=587 --starttls --user=xxxxxxxxxx@yahoo.com --pass=xxxxxxxxxxxxx
sudo: smtp.mail.yahoo.com: command not found
whereis nullmailer
nullmailer: /usr/lib/nullmailer /etc/nullmailer /usr/share/man/man7/nullmailer.7.gz
   sudo /usr/lib/smtp smtp.mail.yahoo.com --auth-login --port=587 --starttls --user=xxxxxxxxxx@yahoo.com --pass=xxxxxxxxxxxxx
sudo: /usr/lib/smtp: command not found
whereis smtp
smtp:
   sudo /etc/nullmailer smtp.mail.yahoo.com --auth-login --port=587 --starttls --user=xxxxxxxxxx@yahoo.com --pass=xxxxxxxxxxxxx
sudo: /etc/nullmailer: command not found
   sudo /etc/nullmailer/remotes
sudo: /etc/nullmailer/remotes: command not found

Ok, seems that yahoo doesn’t works.

Don’t you have a google account? You don’t need to use it, it’s just to use gmail as a bridge to send the emails to yahoo.

I can’t access my gmail account as the recovery info for it is outdated and google isn’t allowing me to get my account info or to get an access code to change my password.

What you mention might work only if I don’t need to actually access my gmail.

Another thought…
The firewall’s in both the access modem router and in Lubuntu is active and running.
Should I set rule’s in one or both to allow what I’m wanting?

Unfortunately that’s what it seems. Just uninstall nullmailer:
apt purge nullmailer
Maybe another user with experience in local mail can help you to setup it.

Probably not. The firewall, unless modified, is enabled allowing all output traffic from LAN.