You are not logged in.

#1 2015-06-19 23:48:26

melw
Member
Registered: 2011-04-09
Posts: 95

[SOLVED]systemd timer issue

So, I've got a small problem with an assignment for my scripting course at the University. Almost there, all i need to do is to get a script to run once a minute. Basicly, i want to run a bash-script called bash_script.sh in the $HOME/projekt folder.

Read man page, wiki and some random stuff after google, but i can't get this thing to run.

Permissions to run the script is ok and the script itself is working properly.

Tried to start and enable both the timer and service with systemctl. Even tried just to start and enable the timer. Also tried with timer and service from both /etc/systemd/system and /usr/lib/systemd/system . Timer seems to be running when using systemctl list-timers .

Now I'm all out of ideas and now need some help.

Timer:

[Unit]
Description=Run wfreq.service every minute
 
[Timer]
OnBootSec=5min
OnUnitActiveSec=1min
Unit=wfreq.service
 
[Install]
WantedBy=multi-user.target

Service:

[Unit]
Description=Run bash_script.sh
 
[Service]
Type=simple
ExecStart=/bin/bash $HOME/projekt/bash_script.sh
 
[Install]
WantedBy=multi-user.target

Last edited by melw (2015-06-20 09:44:11)


I know I'm paranoid, but am I paranoid enought....

Offline

#2 2015-06-20 00:02:22

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: [SOLVED]systemd timer issue

The most glaring issue is that systemd has no idea what $HOME is.  And even if that is passed verbatim to bash and bash interprets it, bash will interpret that as /root/projekt/... which I don't think is what you mean.

Also, type should be 'oneshot', and there should be not [Install] in the service - though i don't know if this would hurt anything.

In the timer, you don't need to specify the service Unit if they have the same base name.  And in the [Install] portion of the timer, it should be timers.target not multi-user.

Lastly, don't enable the service, just the timer.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2015-06-20 00:53:39

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,287

Re: [SOLVED]systemd timer issue

Have you considered making that a user service?

Your script goes into ~/.config/systemd/user/   
Enable it with systemctl --user enable ...  I think you can put a timer in there.  Try it


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#4 2015-06-20 09:24:22

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: [SOLVED]systemd timer issue

You can use %h instead of $HOME after you make it a user service (or set User=).

Trilby wrote:

and there should be not [Install] in the service - though i don't know if this would hurt anything.

[..]

Lastly, don't enable the service, just the timer.

If you don't enable it the [Install] section is simply ignored. Removing the [Install] section would effectively disable the (in this unwanted) enable command for the service.

Offline

#5 2015-06-20 09:43:58

melw
Member
Registered: 2011-04-09
Posts: 95

Re: [SOLVED]systemd timer issue

It's now working.

Made the changes in both timer and service suggested by Trillby. Still had some problem with the script trying to use the wrong directory.
Then i tried the --user version suggested by ewaller and it's now working as it's supposed to.

Thanks to you both!


I know I'm paranoid, but am I paranoid enought....

Offline

Board footer

Powered by FluxBB