systemctl doesn't work from crontab












1















I'm trying to run a script calling systemctl from crontab but the command is not being executed. Other scripts work fine from crontab. The script works when executed in a terminal.



This is the script:



#!/bin/bash

date &>> ~/Desktop/logs/resiliostatus.txt
systemctl --user status resilio-sync | sed -ne '1,3p' &>> ~/Desktop/logs/resiliostatus.txt
exit 0


This is the output to my logfile:



Thu Jan 17 02:17:17 CET 2019
● resilio-sync.service - Resilio Sync service
Loaded: loaded (/usr/lib/systemd/user/resilio-sync.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2019-01-17 01:01:55 CET; 1h 15min ago
Thu Jan 17 03:00:01 CET 2019
Thu Jan 17 04:00:01 CET 2019
Thu Jan 17 05:00:01 CET 2019


The first entry is how it should look like when called from the terminal. But as you can see the calls from crontab only execute date and not systemctl



This is how crontab looks like:



SHELL=/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/lib/systemd

# m h dom mon dow command

*/15 * * * * /root/Desktop/backupscripts/cputempscript
*/30 * * * * /root/Desktop/backupscripts/ipdnsscript
0 * * * * /root/Desktop/backupscripts/ntpscript
*/5 * * * * /root/Desktop/backupscripts/resiliostatscript 2> /tmp/error


The first three scripts work fine, the last one doesnt.
The error I save to /tmp/error: Failed to connect to bus: No such file or directory




  • I'm logged in as root. No other user is logged in. Crontab is configured as sudo crontab -e

  • Environment: Kali Linux (re4son kernel, sticky-fingers) on RPi 3B+

  • I read this similar thread but it is also unresolved.


How can I fix this?










share|improve this question




















  • 1





    fwiw, I would think it is caused by your systems /etc/pam.d/cron not invoking pam_systemd. Some systems do it, and some don't.

    – sourcejedi
    Jan 17 at 14:51











  • there's indeed no hint to pam_systemd in this file. How can I correctly configure this?

    – Bauglir42
    Jan 17 at 14:54











  • well, I tried adding session include pam_systemd.so to /etc/pam.d/cron, not really knowing what I'm doing, rebooted, and apparently that completely broke cron. In var/log/syslog it says CRON[804]: Permission denied. No commands were executed. @sourcejedi

    – Bauglir42
    Jan 17 at 15:29













  • Related questions are unix.stackexchange.com/questions/431896 and unix.stackexchange.com/questions/423632 .

    – JdeBP
    Jan 18 at 0:24
















1















I'm trying to run a script calling systemctl from crontab but the command is not being executed. Other scripts work fine from crontab. The script works when executed in a terminal.



This is the script:



#!/bin/bash

date &>> ~/Desktop/logs/resiliostatus.txt
systemctl --user status resilio-sync | sed -ne '1,3p' &>> ~/Desktop/logs/resiliostatus.txt
exit 0


This is the output to my logfile:



Thu Jan 17 02:17:17 CET 2019
● resilio-sync.service - Resilio Sync service
Loaded: loaded (/usr/lib/systemd/user/resilio-sync.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2019-01-17 01:01:55 CET; 1h 15min ago
Thu Jan 17 03:00:01 CET 2019
Thu Jan 17 04:00:01 CET 2019
Thu Jan 17 05:00:01 CET 2019


The first entry is how it should look like when called from the terminal. But as you can see the calls from crontab only execute date and not systemctl



This is how crontab looks like:



SHELL=/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/lib/systemd

# m h dom mon dow command

*/15 * * * * /root/Desktop/backupscripts/cputempscript
*/30 * * * * /root/Desktop/backupscripts/ipdnsscript
0 * * * * /root/Desktop/backupscripts/ntpscript
*/5 * * * * /root/Desktop/backupscripts/resiliostatscript 2> /tmp/error


The first three scripts work fine, the last one doesnt.
The error I save to /tmp/error: Failed to connect to bus: No such file or directory




  • I'm logged in as root. No other user is logged in. Crontab is configured as sudo crontab -e

  • Environment: Kali Linux (re4son kernel, sticky-fingers) on RPi 3B+

  • I read this similar thread but it is also unresolved.


How can I fix this?










share|improve this question




















  • 1





    fwiw, I would think it is caused by your systems /etc/pam.d/cron not invoking pam_systemd. Some systems do it, and some don't.

    – sourcejedi
    Jan 17 at 14:51











  • there's indeed no hint to pam_systemd in this file. How can I correctly configure this?

    – Bauglir42
    Jan 17 at 14:54











  • well, I tried adding session include pam_systemd.so to /etc/pam.d/cron, not really knowing what I'm doing, rebooted, and apparently that completely broke cron. In var/log/syslog it says CRON[804]: Permission denied. No commands were executed. @sourcejedi

    – Bauglir42
    Jan 17 at 15:29













  • Related questions are unix.stackexchange.com/questions/431896 and unix.stackexchange.com/questions/423632 .

    – JdeBP
    Jan 18 at 0:24














1












1








1








I'm trying to run a script calling systemctl from crontab but the command is not being executed. Other scripts work fine from crontab. The script works when executed in a terminal.



This is the script:



#!/bin/bash

date &>> ~/Desktop/logs/resiliostatus.txt
systemctl --user status resilio-sync | sed -ne '1,3p' &>> ~/Desktop/logs/resiliostatus.txt
exit 0


This is the output to my logfile:



Thu Jan 17 02:17:17 CET 2019
● resilio-sync.service - Resilio Sync service
Loaded: loaded (/usr/lib/systemd/user/resilio-sync.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2019-01-17 01:01:55 CET; 1h 15min ago
Thu Jan 17 03:00:01 CET 2019
Thu Jan 17 04:00:01 CET 2019
Thu Jan 17 05:00:01 CET 2019


The first entry is how it should look like when called from the terminal. But as you can see the calls from crontab only execute date and not systemctl



This is how crontab looks like:



SHELL=/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/lib/systemd

# m h dom mon dow command

*/15 * * * * /root/Desktop/backupscripts/cputempscript
*/30 * * * * /root/Desktop/backupscripts/ipdnsscript
0 * * * * /root/Desktop/backupscripts/ntpscript
*/5 * * * * /root/Desktop/backupscripts/resiliostatscript 2> /tmp/error


The first three scripts work fine, the last one doesnt.
The error I save to /tmp/error: Failed to connect to bus: No such file or directory




  • I'm logged in as root. No other user is logged in. Crontab is configured as sudo crontab -e

  • Environment: Kali Linux (re4son kernel, sticky-fingers) on RPi 3B+

  • I read this similar thread but it is also unresolved.


How can I fix this?










share|improve this question
















I'm trying to run a script calling systemctl from crontab but the command is not being executed. Other scripts work fine from crontab. The script works when executed in a terminal.



This is the script:



#!/bin/bash

date &>> ~/Desktop/logs/resiliostatus.txt
systemctl --user status resilio-sync | sed -ne '1,3p' &>> ~/Desktop/logs/resiliostatus.txt
exit 0


This is the output to my logfile:



Thu Jan 17 02:17:17 CET 2019
● resilio-sync.service - Resilio Sync service
Loaded: loaded (/usr/lib/systemd/user/resilio-sync.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2019-01-17 01:01:55 CET; 1h 15min ago
Thu Jan 17 03:00:01 CET 2019
Thu Jan 17 04:00:01 CET 2019
Thu Jan 17 05:00:01 CET 2019


The first entry is how it should look like when called from the terminal. But as you can see the calls from crontab only execute date and not systemctl



This is how crontab looks like:



SHELL=/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/lib/systemd

# m h dom mon dow command

*/15 * * * * /root/Desktop/backupscripts/cputempscript
*/30 * * * * /root/Desktop/backupscripts/ipdnsscript
0 * * * * /root/Desktop/backupscripts/ntpscript
*/5 * * * * /root/Desktop/backupscripts/resiliostatscript 2> /tmp/error


The first three scripts work fine, the last one doesnt.
The error I save to /tmp/error: Failed to connect to bus: No such file or directory




  • I'm logged in as root. No other user is logged in. Crontab is configured as sudo crontab -e

  • Environment: Kali Linux (re4son kernel, sticky-fingers) on RPi 3B+

  • I read this similar thread but it is also unresolved.


How can I fix this?







scripting cron kali-linux systemctl






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 19 at 19:08









Rui F Ribeiro

39.6k1479132




39.6k1479132










asked Jan 17 at 14:02









Bauglir42Bauglir42

234




234








  • 1





    fwiw, I would think it is caused by your systems /etc/pam.d/cron not invoking pam_systemd. Some systems do it, and some don't.

    – sourcejedi
    Jan 17 at 14:51











  • there's indeed no hint to pam_systemd in this file. How can I correctly configure this?

    – Bauglir42
    Jan 17 at 14:54











  • well, I tried adding session include pam_systemd.so to /etc/pam.d/cron, not really knowing what I'm doing, rebooted, and apparently that completely broke cron. In var/log/syslog it says CRON[804]: Permission denied. No commands were executed. @sourcejedi

    – Bauglir42
    Jan 17 at 15:29













  • Related questions are unix.stackexchange.com/questions/431896 and unix.stackexchange.com/questions/423632 .

    – JdeBP
    Jan 18 at 0:24














  • 1





    fwiw, I would think it is caused by your systems /etc/pam.d/cron not invoking pam_systemd. Some systems do it, and some don't.

    – sourcejedi
    Jan 17 at 14:51











  • there's indeed no hint to pam_systemd in this file. How can I correctly configure this?

    – Bauglir42
    Jan 17 at 14:54











  • well, I tried adding session include pam_systemd.so to /etc/pam.d/cron, not really knowing what I'm doing, rebooted, and apparently that completely broke cron. In var/log/syslog it says CRON[804]: Permission denied. No commands were executed. @sourcejedi

    – Bauglir42
    Jan 17 at 15:29













  • Related questions are unix.stackexchange.com/questions/431896 and unix.stackexchange.com/questions/423632 .

    – JdeBP
    Jan 18 at 0:24








1




1





fwiw, I would think it is caused by your systems /etc/pam.d/cron not invoking pam_systemd. Some systems do it, and some don't.

– sourcejedi
Jan 17 at 14:51





fwiw, I would think it is caused by your systems /etc/pam.d/cron not invoking pam_systemd. Some systems do it, and some don't.

– sourcejedi
Jan 17 at 14:51













there's indeed no hint to pam_systemd in this file. How can I correctly configure this?

– Bauglir42
Jan 17 at 14:54





there's indeed no hint to pam_systemd in this file. How can I correctly configure this?

– Bauglir42
Jan 17 at 14:54













well, I tried adding session include pam_systemd.so to /etc/pam.d/cron, not really knowing what I'm doing, rebooted, and apparently that completely broke cron. In var/log/syslog it says CRON[804]: Permission denied. No commands were executed. @sourcejedi

– Bauglir42
Jan 17 at 15:29







well, I tried adding session include pam_systemd.so to /etc/pam.d/cron, not really knowing what I'm doing, rebooted, and apparently that completely broke cron. In var/log/syslog it says CRON[804]: Permission denied. No commands were executed. @sourcejedi

– Bauglir42
Jan 17 at 15:29















Related questions are unix.stackexchange.com/questions/431896 and unix.stackexchange.com/questions/423632 .

– JdeBP
Jan 18 at 0:24





Related questions are unix.stackexchange.com/questions/431896 and unix.stackexchange.com/questions/423632 .

– JdeBP
Jan 18 at 0:24










0






active

oldest

votes











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f495060%2fsystemctl-doesnt-work-from-crontab%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f495060%2fsystemctl-doesnt-work-from-crontab%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to make a Squid Proxy server?

第一次世界大戦

Touch on Surface Book