4

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?

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
Bauglir42
  • 143
  • 1
  • 7
  • 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 https://unix.stackexchange.com/questions/431896/ and https://unix.stackexchange.com/questions/423632/ . – JdeBP Jan 18 '19 at 00:24

0 Answers0