I have a Raspberry Pi 4 running Debian GNU/Linux 12 (bookworm)
I have a Python script in a shell file launcher.sh (with executable for all permissions) that runs happily without complaint if I initiate it from a remote ssh terminal:
#!/bin/sh
export DISPLAY=:0;/home/craign/main.py
main.py is:
#!/usr/bin/env python3
# sudo apt-get install feh (to show that I've installed feh)
import subprocess
import time
# Display the image
image = subprocess.run(["feh", "--hide-pointer", "-x", "-q", "-F", "-B", "black", "-g", "1280x800", "/home/craign/image.jpg"])
If I try to use cron to execute on boot with (this is sudo crontab -l):
@reboot sh /home/craign/launcher.sh >/home/craign/logs/cronlog 2>&1
In the log file I'm getting
feh ERROR: Can't open X display. It is running, yeah?
Which I don't get if I just run it straight from the default shell that I'm served when I ssh in to the Pi. So I think that somehow I'm not telling the startup script to know what correct environment I'm in.
How can I execute that launcher.sh script on boot so that it knows where the right DISPLAY environment variable points to? I'm not married to this system of using cron to start the program at boot. Any help around getting feh to use the display environment variable set, which is necessary, would be greatly appreciated.