1

I am trying to make a service that sends me a notification every 60 minutes, I made a bash script that does this called hourly.sh, I know that it works becuase I can run it just fine with ./hourly.sh, then I tried to make a timer in order to run this script every 60 minutes but for some unknown reason to me, it isn't working. I started it with systemctl start hourlynotif.timer Here's my code:

hourlynotif.service:

[Unit]
Description=Hourly notifier with notify-send

[Service]
Type=oneshot
ExecStart=/etc/systemd/system/hourly.sh

[Install]
WantedBy=multi-user.target

just a note: I added the [Install] line to try and run it as a service without the timer (because if it's to run as a timer it doesn't need the [Install] label), just to test it, but nothing changed

and hourlynotif.timer:

[Unit]
Description=Hourly notifier with notify-send

[Timer]
#OnCalendar=hourly
OnActiveSec=1

[Install]
WantedBy=timers.target

I know the timer is working as intended because systemctl list-timers --all lists my timer as 'passed', here's the output: (it's not hourly because I edited it to run 1s after started for testing)

NEXT                         LEFT     LAST                         PASSED       UNIT                         ACTIVATES

n/a                          n/a      Thu 2017-08-31 05:21:54 CST  6s ago       hourlynotif.timer            hourlynotif.service

any ideas?

Edit: the bash script relies on notify-send, which relies on KDE notification widget to be displayed. If I sudo the script it doesn't trigger the notification, so I believe I need to run the script with the user that I'm logged in at.

6
  • So does systemctl start hourlynotif.service work as expected? It would be also better to move the desired configuration which might be wrong but you can post erros which give hints which gives people the ability to help you.
    – Thomas
    Commented Aug 31, 2017 at 11:36
  • @Thomas move the desired configuration? what do you mean by this? Also no, the service is not running the .sh script when i do systemctl start hourlynotif.service
    – Jose V
    Commented Aug 31, 2017 at 11:38
  • @Thomas i think the problem is that im not running the script with the same user that im logged in, it's probably running as root.
    – Jose V
    Commented Aug 31, 2017 at 11:43
  • Sorry, use instead of move. Well now you have configured 1second-after-start, but actually you want to run it every 60 minutes. When you do systemctl start hourlynotif.service, do you get any errors? Any output of systemctl status hourlynotif.service or journalctl -u hourlynotif.service? Please add that to your question
    – Thomas
    Commented Aug 31, 2017 at 11:44
  • 1
    is your notification script relying on user-level environment variables to contact you? (DISPLAY, etc)
    – Jeff Schaller
    Commented Aug 31, 2017 at 12:01

1 Answer 1

1

The problem was that I wasn't running it with systemctl --user start <unit>, I was using just systemctl start <unit>. The bash script relies on user-specific KDE stuff, so running the script with sudo didn't work, which is the default mode for services.

3

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .