This error may be specific to systemd - or perhaps bluetooth :
This is a "headless" system. I would like to auto-connect my BT speaker after a reboot. Before upgrading my system from 'bookworm' to 'trixie', my (headless) system did this with no help or input from me! IOW, I didn't do anything specific during the original install/config to cause it to auto-connect the speaker at reboot; consequently I don't know where to begin to restore that. However:
I use bluetoothctl to handle my BT "configuration" tasks; for example, I can issue a command to connect my speaker: bluetoothctl connect <device-id>. I also know that systemd services bluetooth and pipewire must be "active" before a speaker connection can be made. And so in an effort to replace my former auto-connect, I wrote a short script that I could run from a user cron job:
The cron job:
@reboot /home/my/blueboot.sh >> /home/my/blueboot.log 2>&1 #!/usr/bin/env bash # Purpose: auto-connect BT speaker LOGFILE="/home/my/blueboot.log" n=0 until systemctl is-active --quiet bluetooth && systemctl --user --quiet is-active pipewire do n=$((n + 1)) /usr/bin/sleep 1 done /usr/bin/echo "Seconds waited for bluetooth & pipewire services: $n" >> $LOGFILE /usr/bin/bluetoothctl connect B8:F6:53:AE:13:F1 >> $LOGFILE In my blueboot.log file I get the following error message repeated many times:
Failed to connect to user scope bus via local transport: $DBUS_SESSION_BUS_ADDRESS and $XDG_RUNTIME_DIR not defined (consider using --machine=<user>@.host --user to connect to bus of other user) And of course no speaker connection.
It seems the problem is with the status check I am trying to do on pipewire. I've tried running the cron job under /etc/crontab with the user prefix:
@reboot my /home/my/blueboot.sh >> /home/my/blueboot.log 2>&1 But this does not seem to help. Nevertheless, I need to wait on bluetooth and pipewire services to be active before I can issue a successful command to bluetoothctl connect <device-id>.
How can I overcome this error, and get the status of pipewire.service from a cron job?
systemdservices./etc/systemd/user/(or~/.config/systemd/user/if you want it to be available for just one/some specific user) instead of/etc/systemd/system/. (The user manager supplies user services with the two env var mentioned in the error btw.)bluetooth.service(which is a system one), since technically it's pulled in as of the enumeration of a bluetooth controller. With that said you probably don't need to do that anyway, since IIRC bluetoothctl would "block" until the service comes up.pipewire.serviceon the other hand is a user service.