I can't figure out cron

Linux Mint 20.3
Cinnamon 5.2.7

I’ve never used cron to schedule anything before and I’m trying to learn how this works with the simplest of commands.

I edit the crontab file for my user with

crontab -e

I put in this command

* * * * * /usr/bin/notify-send "cron test" >/dev/null 2>&1

In theory this should send a notification to my desktop every minute.

I restart the cron service

service cron restart

I enter the super user credentials and the service restarts. However, no notifications ever show up.
I’ve checked the /etc/cron.allow and /etc/cron.deny file but neither of them exist so it should default to allowing every user access to cron right?

I confirm the crontab file is correct with

crontab -u <username> -l

I created the /etc/cron.allow file and added my user to it, restarted the service, and that didn’t work either.

I added my user to the crontab group as well but still nothing.

I can confirm that the /usr/bin/notify-send "cron test" >/dev/null 2>&1 command works on its own in a terminal.

If you tell your user’s cron to create a file in your home directory it’ll work:

* * * * * touch /home/<USER HERE>/test

If you try to use notify-send it won’t.

I don’t know the exact reason but i’m guessing cron is somehow run outside the scope of your window session so you can’t interact like you would from within it.

First see if your crontab is being executed by looking at the syslog:
tail /var/log/syslog

Cron runs headless. So cron won’t send a notification to the same location as the user who attempts to send the notification. You have to tell cron where to send the notification.

See what your display number is with:

 echo $DISPLAY 

My machine reports:


So what you need to do is tell cron to display the message on your :0 Display. Like this:

* * * * * export DISPLAY=:0; /usr/bin/notify-send "cron test" >/dev/null 2>&1

1 Like

Ah, nice. This one works. I wasn’t going simple enough apparently.

This isn’t working unfortunately. My display is :0 like yours. This was only for testing anyways and not what I actually wish to implement so it’s all good. Now that I think of it, it could be kinda useful to set desktop notification to remind me of various things throughout the day. Hmmmm

After looking at the syslog I saw CRON was trying to email me but there was no mail service installed. When I installed postfix I could see this error in the messages.

Unable to init server: Could not connect: Connection refused
# Failed to parse arguments: Cannot open display: