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:


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:


# 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?

  • 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 '19 at 14:51
  • there's indeed no hint to pam_systemd in this file. How can I correctly configure this? – Bauglir42 Jan 17 '19 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 '19 at 15:29
  • Related questions are unix.stackexchange.com/questions/431896 and unix.stackexchange.com/questions/423632 . – JdeBP Jan 18 '19 at 0:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.