The information message:
(CRON) info (No MTA installed, discarding output)
Is not your issue ... It simply means that your crnjob resulted in an output that you didn't provide a method for it to be redirected/handled(Notice: That output could be some useful information and maybe you should redirect it to a file for later inspection) and CRON in this case tries to email the output but doesn't succeed due to absence of MTA(Mail Transfer Agent) ... It's totally a normal behavior and installing an MTA will not make your cronjob execute better ... Please see Cron job log reads 'No MTA installed', does that prevent the CRON job from finishing?
Your issue, most likely, is that xmessage
is an X-based application that requires an X server user session already running plus a display interface/server specified ... If your cronjob is guaranteed to run while an X server user session is already running and not otherwise, then you might be able to make it work if you find and specify the address of your display interface/server as an environment variable before your command in the crontab e.g. like so:
* * * * * DISPLAY=":0" your_command ...
You can see your current environment $DISPLAY
variable while your user X session is running e.g. like so:
echo $DISPLAY
and even though, CRON might run your command before an X user session is even fully initiated in case of e.g. @reboot
is specified or the user has logged out their session for some reason at the time CRON runs your command.
Notice also that if you add your command to root
's crontab with sudo crontab -e
then your X-based application might not run no matter what you do as root
on Ubuntu, by default, can't start an X session.
Therefore given the above reasons, CRON is not by all means the preferred way for running X-based user applications.
Otherwise, I recommend you run your X-based script/command as a startup application ... Please see Startup script not executing for similar issue and possible workaround.
Also, please see Battery Full Indicator 22.04 for an example of a battery monitoring script that can be used in a startup application instead of a cronjob.
xmessage
is X-based ... i.e. requires a user's X session(You might manage to run it with CRON if you specify a display environment variable e.g. DISPLAY=":0" before your command) ... Please se similar question: https://askubuntu.com/q/1450604/968501 – Raffa Jan 26 '23 at 18:49