2016-03-23 1:32 GMT+01:00 Kai Krakow <hurikha...@gmail.com>:

> Am Mon, 21 Mar 2016 09:21:39 +0100
> schrieb Cecil Westerhof <cldwester...@gmail.com>:
>
> > When executing
> >     systemctl suspend || echo "Error code: ${?}"
> > from the command-line it outputs
> >     Error code: 1
> > and it puts my machine in suspend.
> >
> > When putting it in cron it gives the following errors:
> >     Failed to execute operation: Access denied
> >     Failed to start suspend.target: Access denied
> > and gives the output:
> >     Error code: 4
> >
> > What is happening here? Is it possible to run 'systemctl suspend' from
> > cron, or is there a reason why this is not possible?
>
> It's probably because cron doesn't setup a systemd session. Do you
> eventually run from a user crontab?


​I am not sure what you mean here. It was run from my user crontab. It is a
simplification from what I want. I have a script that I like to put into
systemd as a service, but there I get this error.


Have you tried running from a root
> crontab?
>

​Just tried it and that works. One important difference: it returns an
error code of 0 instead of 1.
So probably I need to setup a systemd session. How am I going to do that?


​I would not want to run the script as root.​ The script is:
    https://github.com/CecilWesterhof/BashLibrary/blob/master/bin/suspend.sh
Besides that I do not want to run a script as root when not necessary, with
root in cron you get:
    No protocol specified
    xscreensaver-command: can't open display :0.0
​with the initial while.​ Which I do not get when running as normal user.


​If you wondering why I wrote the script:

https://www.linkedin.com/pulse/saving-netbook-battery-bash-script-cecil-westerhof
​

-- 
Cecil Westerhof
_______________________________________________
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel

Reply via email to