Context - Ich habe ein Python-Skript, das Musik-Ordner liest und öffnet VLC-Player für jede Musikdatei eins nach dem anderen (1 Lied wird gespielt, VLC wird geschlossen und dann wird ein anderes so weiterspielen und so weiter). Wenn ich das Python-Skript von IDE oder Terminal ausführe, wird das Skript erfolgreich ausgeführt. Wenn ich es jedoch über den Cron-Job ausführe, schlägt es fehl.Python-Skript geplant durch Cron Job ist fehlgeschlagen
Python-Skript - Bitte beachten Sie, ich habe die Schleife für Testzwecke deaktiviert.
import os,subprocess
my_path = '/home/tushar/Music/Devotional/'
songs_list = os.listdir(my_path)
song_str = ''
#for song in songs_list:
#subprocess.run(["vlc", my_path+song])
subprocess.run(["vlc", "/home/tushar/PycharmProjects/Morning Devotional Songs/Ganesha.opus"])
crontab -e
47 10 * * * python3 /home/tushar/PycharmProjects/Morning\ Devotional\ Songs/main.py >> /var/log/myjob.log 2>&1
Cron Job-Protokoll -
> [000055ed64567cf8] core interface error: no suitable interface module
> [000055ed6445a148] core libvlc error: interface "globalhotkeys,none"
> initialization failed [000055ed64567cf8] dbus interface error: Failed
> to connect to the D-Bus session daemon: Unable to autolaunch a
> dbus-daemon without a $DISPLAY for X11 [000055ed64567cf8] core
> interface error: no suitable interface module [000055ed6445a148] core
> libvlc error: interface "dbus,none" initialization failed
> [000055ed6445a148] core libvlc: Running vlc with the default
> interface. Use 'cvlc' to use vlc without interface. [000055ed64567cf8]
> qt4 interface error: Could not connect to X server [000055ed64567cf8]
> skins2 interface error: cannot initialize OSFactory [000055ed64567cf8]
> [cli] lua interface: Listening on host "*console". VLC media player
> 2.2.4 Weatherwax Command Line Interface initialized. Type `help' for help.
>
> Shutting down. [000055ed64567cf8] [cli] lua interface: Requested
> shutdown. [000055ed64567cf8] [cli] lua interface error: Error loading
> script /usr/lib/vlc/lua/intf/cli.luac: lua/intf/modules/host.lua:279:
> Interrupted. [00007f977c0178c8] core stream error: cannot pre fill
> buffer
Wie behebe ich das Problem?
Das liegt daran, dass Jobs, die über cron ausgeführt werden, keine DISPLAY-Umgebungsvariable haben (dh standardmäßig nicht im GUI-Modus) und nicht mit dem Display-Server kommunizieren können. Entweder setze die Anzeigevariable (hackish) oder wie der Fehler sagt 'cvlc'. – SuperSaiyan