<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2016-03-23 1:32 GMT+01:00 Kai Krakow <span dir="ltr"><<a href="mailto:hurikhan77@gmail.com" target="_blank">hurikhan77@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Am Mon, 21 Mar 2016 09:21:39 +0100<br>
schrieb Cecil Westerhof <<a href="mailto:cldwesterhof@gmail.com">cldwesterhof@gmail.com</a>>:<br>
<span class=""><br>
> When executing<br>
> systemctl suspend || echo "Error code: ${?}"<br>
> from the command-line it outputs<br>
> Error code: 1<br>
> and it puts my machine in suspend.<br>
><br>
> When putting it in cron it gives the following errors:<br>
> Failed to execute operation: Access denied<br>
> Failed to start suspend.target: Access denied<br>
> and gives the output:<br>
> Error code: 4<br>
><br>
> What is happening here? Is it possible to run 'systemctl suspend' from<br>
> cron, or is there a reason why this is not possible?<br>
<br>
</span>It's probably because cron doesn't setup a systemd session. Do you<br>
eventually run from a user crontab?</blockquote><div><br><div class="gmail_default" style="font-family:courier new,monospace;display:inline">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.<br><br><br></div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> Have you tried running from a root<br>
crontab?<br></blockquote><div><br><div class="gmail_default" style="font-family:courier new,monospace;display:inline">Just tried it and that works. One important difference: it returns an error code of 0 instead of 1.<br>So probably I need to setup a systemd session. How am I going to do that?</div></div></div><br><br><div class="gmail_default" style="font-family:courier new,monospace">I would not want to run the script as root. The script is:<br> <a href="https://github.com/CecilWesterhof/BashLibrary/blob/master/bin/suspend.sh">https://github.com/CecilWesterhof/BashLibrary/blob/master/bin/suspend.sh</a><br></div><div class="gmail_default" style="font-family:courier new,monospace">Besides that I do not want to run a script as root when not necessary, with root in cron you get:<br></div><div class="gmail_default" style="font-family:courier new,monospace"> No protocol specified<br></div><div class="gmail_default" style="font-family:courier new,monospace"> xscreensaver-command: can't open display :0.0<br></div><div class="gmail_default" style="font-family:courier new,monospace">with the initial while. Which I do not get when running as normal user.<br><br></div><br><div class="gmail_default" style="font-family:courier new,monospace">If you wondering why I wrote the script:<br> <a href="https://www.linkedin.com/pulse/saving-netbook-battery-bash-script-cecil-westerhof">https://www.linkedin.com/pulse/saving-netbook-battery-bash-script-cecil-westerhof</a></div><br>-- <br><div class="gmail_signature">Cecil Westerhof</div>
</div></div>