Cron not executing a command

If I type the following into terminal, I get a notify in the upper right corner of my screen
that reads 'Test 13:55' (without the quotes):

/usr/bin/notify-send -t 82800000 'Test 13:55'

But if I put it into my crontab, when 13:55 rolls around, I get no notification.
My crontab entry reads:

55 13 * * * /usr/bin/notify-send -t 82800000 'Test 13:55'

Any idea how I can get the notification?

55 13 * * * env DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus /usr/bin/notify-send -t 82800000 "Test 13:55"

Note: user should be your login, larry eg. /run/larry/$(id -u)/bus

2 Likes

That didn't work. Is there anything else I should change in the line?
I put this in (yes, username is larry):

20 10 * * * env DBUS_SESSION_BUS_ADDRESS=unix:path=/run/larry/$(id -u)/bus /usr/bin/notify-send -t 82800000 "Test 10:20"

Not sure but looks like your spacking is different than @pavlos_kairis in the three * and the -t82xxx command. Just an idea.

The only difference is in the actual numbers I am using to test, and the different lengths of 'larry' and 'user'.

Quick question.. does crontab get reloaded every minute? When testing, I have been allowing about 3-5 minutes past when I save the crontab file.

I should mention that I have several crontab entries that do work. Two that call backup scripts, and two that write a date to a file.

Sorry my error on my screen the code pasted looks different from your pasted probably due to font. Sorry again, disregard.

I tested on um22. When you type notify-send "hello" in a term, it does pop a notification.

Then, crontab -e, added my line:

52 9 * * * env DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus /usr/bin/notify-send "some test"

if the command fails, the will be a mail generated which you can view with mail

Look at the end of syslog, cat /var/log/syslog you will see:

Nov  3 09:49:39 um22 crontab[2470]: (user) BEGIN EDIT (user)
Nov  3 09:49:57 um22 crontab[2470]: (user) REPLACE (user)
Nov  3 09:49:57 um22 crontab[2470]: (user) END EDIT (user)
Nov  3 09:50:01 um22 cron[579]: (user) RELOAD (crontabs/user)
Nov  3 09:52:01 um22 CRON[2483]: (user) CMD (env DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus /usr/bin/notify-send "some test" )
Nov  3 09:52:01 um22 dbus-daemon[941]: [session uid=1000 pid=941] Activating service name='org.freedesktop.Notifications' requested by ':1.62' (uid=1000 pid=2485 comm="/usr/bin/notify-send some test " label="unconfined")
Nov  3 09:52:01 um22 dbus-daemon[941]: [session uid=1000 pid=941] Successfully activated service 'org.freedesktop.Notifications'

(this tells me crontab -e worked and then the command worked, CRON sent the command, dbus-daemon got it, and successfully activated service notifications at 09:52)

Usually CRON is used for non GUI setups, as you wrote, back this or backup that. When GUI is involved you have to understand DBUS and how it works. Hope this helps.

2 Likes

Interesting. I see a problem. I don't get an email, but when I cat /var/log/syslog I get...

Nov 3 22:30:01 Whizz CRON[4091]: (larry) CMD (env DBUS_SESSION_BUS_ADDRESS=unix:path=/run/larry/$(id -u)/bus /usr/bin/notify-send -t 82800000 "Test 22:30")

Nov 3 22:30:01 Whizz CRON[4088]: (CRON) info (No MTA installed, discarding output)

A little Googling tellg me MTA is a Mail Transfer Agent. Should I install sendmail? postfix? or?

I have postfix installed so that those errors go to my mail system. If you google "No MTA installed" there are various solutions, like throw the output away with /dev/null 2>&1

REF: "(CRON) info (No MTA installed, discarding output)" error in the syslog - Ask Ubuntu

1 Like

I tried putting MAILTO="" at the top of my crontab entries, and now the 'No MTA' error goes away, but I still get no notification.

Output from 'cat /var/log/syslog' is:

Nov 4 10:03:01 Whizz CRON[30953]: (larry) CMD (env DBUS_SESSION_BUS_ADDRESS=unix:path=/run/larry/$(id -u)/bus /usr/bin/notify-send -t 82800000 "Test")
Nov 4 10:03:35 Whizz dbus-daemon[1545]: [session uid=1000 pid=1545] Activating service name='org.freedesktop.Notifications' requested by ':1.80' (uid=1000 pid=3177 comm="evolution " label="unconfined")
Nov 4 10:03:35 Whizz dbus-daemon[1545]: [session uid=1000 pid=1545] Successfully activated service 'org.freedesktop.Notifications'
Nov 4 10:03:35 Whizz mate-notificati[30971]: g_object_unref: assertion 'G_IS_OBJECT (object)' failed
Nov 4 10:10:01 Whizz CRON[31246]: (larry) CMD (/usr/bin/date >/media/larry/Elements/.date)
Nov 4 10:10:01 Whizz CRON[31250]: (larry) CMD (/usr/bin/date >/home/larry/bin/foo)
Nov 4 10:17:01 Whizz CRON[31414]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)

The mail I talk about is the UNIX mail in your system, not your gmail or whatever. All UNIX/Linux systems has a mail subsystem so when something goes wrong, it sends mail to that pc which you can read using the command mail. Mail is stored in /var/mail/

According to your log, it sent the notification at 10:03 but the next line shows an issue.

1 Like

First, thanks for the help. It's appreciated.

I finally asked a friend that has been using MATE for many years, and he pointed out the error.

Here's what works...

          • DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u larry)/bus /usr/bin/notify-send "Test"

This is wrong ... path=/run/user/ does not exist in your system.

It should be, path=/run/larry/$(id -u)/bus

There is a tmpfs mount in df

tmpfs             812800      124    812676   1% /run/larry/1000

The -t parameter should work, I don't understand why you need the notification to be active for 23 hours (828000000). I tried with -t 60000 (1 min) and it worked.

Maybe use Stickynotes - Learn Ubuntu MATE

1 Like

What can I say? It works.

OK, but what has that got to do with it?

The -t parameter does work.
An actual example that does work is:

25 09 * * * DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u larry)/bus /usr/bin/notify-send -t 82800000 "Test "

As for why I used 828000000, I wanted the notification to be up until I clicked on it to dismiss it, and if I set cron to do it at 00:01 it will be there whenever I happen to look at it. Using 6000 (1 minute) would almost guarantee that I would miss it.

I took a look at the link, but I don't see any reference to an ability to bring up a note at a particular date, time, day of week, etc,

I am happy with what I have now, using cron.

First, you do not have a $USER named user in your system therefore /run/user/ would not exist.
Unless you created a user login so under /home there would be two accounts, /home/larry/ and /home/user/

Second, tmpfs is used to pass information between the $USER and the bus. It needs a valid mount point to pass information. Since your only $USER is larry, the only valid mount point would be /run/larry/1000/

Third, just because something works does not mean it is right.

Fourth, please paste the output of df

As for stickynotes, I created one that reads, "buy coffee tomorrow." It will stay on my screen until I buy coffee and get rid of the stickynote. The idea that I want cron to keep monitoring for 23 hours is difficult to understand.

[quote="pavlos_kairis, post:15, topic:26952, full:true"]
First, you do not have a $USER named user in your system therefore /run/user/ would not exist.
Unless you created a user login so under /home there would be two accounts, /home/larry/ and /home/user/[/quote]

larry@Whizz:~$ ls /run/user
1000
larry@Whizz:~$ ls /run/user/1000/
at-spi doc gvfs pipewire-0 speech-dispatcher
bus geany gvfsd pipewire-0.lock systemd
dbus-1 gnupg ICEauthority pk-debconf-socket update-notifier.pid
dconf gui.lock keyring pulse webkitgtk
larry@Whizz:~$

[quote=Second, tmpfs is used to pass information between the $USER and the bus. It needs a valid mount point to pass information. Since your only $USER is larry, the only valid mount point would be /run/larry/1000/[/quote]

OK. But I do not have a 'larry' in /run.
larry@Whizz:~$ ls /run/
acpid.pid expressvpn openvpn teamviewerd.ipc
acpid.socket fsck openvpn-client teamviewerd.pid
agetty.reload initctl openvpn-server thermald
alsa initramfs plymouth tlp
avahi-daemon irqbalance samba tmpfiles.d
blkid lightdm sendsigs.omit.d udev
console-setup lightdm.pid shm udisks2
credentials lock speech-dispatcher unattended-upgrades.lock
crond.pid log spice-vdagentd user
crond.reboot motd.d sshd utmp
cryptsetup mount sshd.pid uuidd
cups network sudo
dbus NetworkManager systemd

If it matters, my Ubuntu is
Ubuntu 22.04.3 LTS
Release: 22.04
Codename: jammy
MATE: 1.26.0

[quote=Third, just because something works does not mean it is right.[/quote]

Right. But is the fact that there is a /run/user the reason for it working?
It did not work with /run/larry and it looks like the reason is that there is no /run/larry

[quote=Fourth, please paste the output of df. [/quote]

Filesystem Size Used Avail Use% Mounted on
tmpfs 3.2G 1.4M 3.2G 1% /run
/dev/sda5 457G 21G 414G 5% /
tmpfs 16G 0 16G 0% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
/dev/sda1 511M 4.0K 511M 1% /boot/efi
/dev/sdd2 2.7T 661G 2.0T 26% /media/larry/Modata
/dev/sdb1 5.5T 3.5T 1.7T 68% /media/larry/Elements
/dev/sdd1 903G 83G 775G 10% /home
tmpfs 3.2G 1.7M 3.2G 1% /run/user/1000
/dev/sdc2 224G 6.8G 217G 4% /media/larry/SSD

OK, but how would I remind myself to change the furnace filter every two months?
Would I have to have a large number of Stickynotes cluttering up my desktop?

The reason for wanting a long t- value is that I want the notification up on my screen when I am done all the things I need to do in the morning, and sometimes, even on into the afternoon and evening. I never know when I'll get around to the computer. cron currently does the job I want it to do. If you can point out a downside to what I am now using, I'd consider changing it.

Stickynotes would probably work for me if I can call them with cron on the when they are relevant.

It seems your friend (who knows mate) made stuff to make it work. Maybe he created a /run/user/ path or made a symbolic link /run/user/ -> /run/larry/

You should have one user in your system, larry. Upon login you should have /home/larry/ with uid=1000, and gid=1000 I see from your login, user is larry. tmpfs should point to /run/larry/1000 like you have some disks attached and they are mounted under /media/larry/

BTW, when you paste output, please select it and format it with the </> symbol which makes it fixed font and it is easier to read.

It seems your friend (who knows mate) made stuff to make it work. Maybe he created a /run/user/ path or made a symbolic link /run/user/ -> /run/larry/

He did not. He is running Ubuntu 20.04, and has the same situation in that his /run/user directory is the same as mine.

I also checked one of my laptops that has Ubuntu 20.04, installed, as was my desktop, from a downloaded image via a USB thumb drive, and has had no modifications to it, other than setting up the WiFi. I installed both from the same thumb drive. I have since upgraded my desktop machine to 22.04

You should have one user in your system, larry. Upon login you should have /home/larry/ with uid=1000, and gid=1000 I see from your login, user is larry. tmpfs should point to /run/larry/1000 like you have some disks attached and they are mounted under /media/larry/

I really don't know what's happening, but if your /run has no 'user' subdirectory, I can only surmise that it was because the first Ubuntu version you installed on your machine was not 20.04

BTW, when you paste output, please select it and format it with the </> symbol which makes it fixed font and it is easier to read.

Tried, but I probably did it incorrectly.

2 Likes

I created a fresh um22 VM with username larry. I noticed that the tmpfs mount point is /run/user/1000 which means I was wrong. I got confused since my username in the other VM is user. The correct crontab line should be: (without larry).

25 09 * * * DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus

$(id -u) will pick the correct uid of the username, it could be 1000 or 1001 or ...

Sorry about the confusion.

2 Likes

"pavlos_kairis
I created a fresh um22 VM with username larry. I noticed that the tmpfs mount point is /run/user/1000 which means I was wrong. I got confused since my username in the other VM is user. The correct crontab line should be: (without larry).

25 09 * * * DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus $(id -u)
will pick the correct uid of the username, it could be 1000 or 1001 or ...

Yup. That works. The other thing that my friend mentioned is that I can use
notify-send -t 0
to set the notification to infinite, meaning that even if I am away for few days, the notification will still be there.

Sorry about the confusion.

No problem. I appreciate the help, and we both learned something.

Now, how, exactly, can I set monospaced font. I wasn't sure how to do it from your description.
Or better still, is there anything on this site that shows the markdown syntax?

2 Likes