# \[Tutorial\] systemd timer that can send a notification:

**URL:** <https://forum.endeavouros.com/t/tutorial-systemd-timer-that-can-send-a-notification/48007>\
**Category:** Wiki entry\
**Created:** [November 19, 2023, 3:47pm UTC](https://forum.endeavouros.com/t/tutorial-systemd-timer-that-can-send-a-notification/48007 "2023-11-19T15:47:56Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![xircon](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/xircon/32/9124_2.png) [@xircon](https://forum.endeavouros.com/u/xircon)\
**Post date:** [November 19, 2023, 3:47pm UTC](https://forum.endeavouros.com/t/tutorial-systemd-timer-that-can-send-a-notification/48007/1 "2023-11-19T15:47:56Z")

</div>

This has taken me nearly a day and a lot of reading to get it to work!

Scenario - I wanted a notification every n minutes of any updates available, but this is easily adapted to other uses, just change the script.

1. The script (uses auracle & checkupdates):

```auto
#!/usr/bin/env bash

# Run by /etc/systemd/system/archup.service + timer

export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$UID/bus"

echo $(date) > ~/.avail.txt

/usr/bin/checkupdates >> ~/.avail.txt

echo "-----------------------------------------------" >> ~/.avail.txt

/usr/bin/auracle outdated >> ~/.avail.txt

notify-send "$(cat ~/.avail.txt)"

echo $(date) >> ~/test 

```

The export DBUS\_SESSION… is the important line, if it is missing, the following error occurs:

```auto
Cannot autolaunch D-Bus without X11 $DISPLAY

```

1. The service:

```auto
# /etc/systemd/system/archup.service
[Unit]
Description=Service to run update notifier:

[Service]
Type=oneshot
ExecStart=/usr/bin/uup
User=xircon

```

The important line here is `User=<your-user>`. `/usr/bin/uup` is a symlink to the script.

1. The Timer:

```auto
# /etc/systemd/system/archup.timer
[Unit]
Description=Logs some system statistics to the systemd journal

[Timer]

# Explained https://silentlad.com/systemd-timers-oncalendar-(cron)-format-explained

# Testing - Every 1 minute:
#OnCalendar=*:1/1

# Deployment - Every 30 minutes:
OnCalendar=*:0/30:00

Unit=archup.service

[Install]
WantedBy=multi-utimers.target

```

1. Start the timer:

```auto
sudo systemctl enable archup.timer --now

```

A notification can be forced with:

```auto
sudo systemctl restart archup.timer

```

 ![image](https://forum.endeavouros.com/uploads/default/original/3X/6/4/6441796ab031ef858acfa650899a82a2e643134c.jpeg)

---

<div class="post-metadata">

**Author:** ![xircon](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/xircon/32/9124_2.png) [@xircon](https://forum.endeavouros.com/u/xircon)\
**Post date:** [November 19, 2023, 4:06pm UTC](https://forum.endeavouros.com/t/tutorial-systemd-timer-that-can-send-a-notification/48007/2 "2023-11-19T16:06:54Z")

</div>

Am now working on a gmail script, will post it when I get it working…

---

<div class="post-metadata">

**Author:** ![BS86](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/bs86/32/18119_2.png) [@BS86](https://forum.endeavouros.com/u/BS86)\
**Post date:** [November 19, 2023, 6:34pm UTC](https://forum.endeavouros.com/t/tutorial-systemd-timer-that-can-send-a-notification/48007/3 "2023-11-19T18:34:22Z")

</div>

why not simply use the `eos-update-notifier` package from the repo?

If you want more functions in there, you might be able to contribute to that one as it is EndeavourOS maintained.

---

<div class="post-metadata">

**Author:** ![xircon](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/xircon/32/9124_2.png) [@xircon](https://forum.endeavouros.com/u/xircon)\
**Post date:** [November 19, 2023, 6:36pm UTC](https://forum.endeavouros.com/t/tutorial-systemd-timer-that-can-send-a-notification/48007/4 "2023-11-19T18:36:41Z")

</div>

Because I am trying to learn eww and needed something to integrate with it.

---

<div class="post-metadata">

**Author:** ![voryzen](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/voryzen/32/66893_2.png) [@voryzen](https://forum.endeavouros.com/u/voryzen)\
**Post date:** [November 20, 2023, 11:38pm UTC](https://forum.endeavouros.com/t/tutorial-systemd-timer-that-can-send-a-notification/48007/5 "2023-11-20T23:38:52Z")

</div>

> [@xircon](#):
>
> I am trying to learn eww

What is that?

---

<div class="post-metadata">

**Author:** ![anon93652015](https://forum.endeavouros.com/letter_avatar_proxy/v4/letter/a/48db29/32.png) [@anon93652015](https://forum.endeavouros.com/u/anon93652015)\
**Post date:** [November 21, 2023, 12:32am UTC](https://forum.endeavouros.com/t/tutorial-systemd-timer-that-can-send-a-notification/48007/6 "2023-11-21T00:32:12Z")

</div>

🤮 😅

---

<div class="post-metadata">

**Author:** ![ajgringo619](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/ajgringo619/32/35599_2.png) [@ajgringo619](https://forum.endeavouros.com/u/ajgringo619)\
**Post date:** [November 21, 2023, 12:42am UTC](https://forum.endeavouros.com/t/tutorial-systemd-timer-that-can-send-a-notification/48007/7 "2023-11-21T00:42:36Z")

</div>

Learning is always a good thing. But I don’t understand why you’re adding in extra hoops here. As mentioned above, the `eos-update-notifier` script will generate a notification for the current user…because the systemd service the timer calls is run as a user service, installed in `$HOME/.config/systemd/user`. If you look at the service, you’ll that it only needs to add the `DISPLAY=:0` variable to the environment before running:

```auto
# /home/ajgringo619/.config/systemd/user/eos-update-notifier.service
[Unit]
Description=EOS update notifier service

[Service]
Type=oneshot
Environment=DISPLAY=:0
ExecStart=/usr/bin/eos-update-notifier -systemd

[Install]
WantedBy=eos-update-notifier.timer

```

IMHO, a better project would be to learn about sending system notifications to logged in users.

---

<div class="post-metadata">

**Author:** ![anon26269396](https://forum.endeavouros.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@anon26269396](https://forum.endeavouros.com/u/anon26269396)\
**Post date:** [November 21, 2023, 12:43am UTC](https://forum.endeavouros.com/t/tutorial-systemd-timer-that-can-send-a-notification/48007/8 "2023-11-21T00:43:22Z")

</div>

> [@voryzen](#):
>
> What is that?

> **[GitHub - elkowar/eww: ElKowars wacky widgets](https://github.com/elkowar/eww)**
>
> ElKowars wacky widgets. Contribute to elkowar/eww development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![anon93652015](https://forum.endeavouros.com/letter_avatar_proxy/v4/letter/a/48db29/32.png) [@anon93652015](https://forum.endeavouros.com/u/anon93652015)\
**Post date:** [November 21, 2023, 12:50am UTC](https://forum.endeavouros.com/t/tutorial-systemd-timer-that-can-send-a-notification/48007/9 "2023-11-21T00:50:16Z")

</div>

When learning an instrument, we are taught to play the same notes as someone else. When we do it well enough, and like it, we experiment and make our own music.

In other words, we learn to recreate something from scratch that has already been made so we can create something entirely new. 🤔
