0

I have set up a testing script to play videos on VLC-3.0.12 (Manjaro) using crontab (cronie-1.5.7). The file in question looks like this:

#!/bin/bash
## YES, I'M RICKROLLING MYSELF FOR TESTING

[[ "$HOME" != "/home/drjeff16" ]] && exit 1
[[ -n "$(pgrep vlc)" ]] && exit 1

# SINCE CRON DOES NOT SET THE EXISTING X11 ENV VARS, SET THE DISPLAY MANUALLY
DISPLAY=:0.0

if [[ "$isCron" == "0" ]] ; then                                # IF RUNNING FROM REGULAR TERMINAL ENVIRONMENT
  echo '[[ -n "$(pgrep vlc)" ]] && killall vlc' | /usr/bin/at now + 5 minutes
  nhp vlc "$HOME"/Videos/Music/Never-Gonna-Give-You-Up.mp4      # 'nhp' IS 'nohup <command> &!' AS AN EXPORTED
                                                                # FUNCTION TO AVOID APPS HIJACKING MY TERMINAL
  exit 0
elif [[ "$isCron" == "1" ]] ; then                              # ELSE IF RUNNING FROM CRONTAB ($isCron IS 1 ON CRON ENV)
  echo '[[ -n "$(pgrep vlc)" ]] && killall vlc' | /usr/bin/at now + 5 minutes
  vlc "$HOME"/Videos/Music/Never-Gonna-Give-You-Up.mp4
  exit 0
fi

exit 1

Executing this script from my normal environment does not cause any issues. However, when running it from crontab, VLC does run and display video, but no audio comes out anywhere.

While reading the manual entry for VLC man vlc, I came across the $OSSAUDIO_DEV variable in the ENVIRONMENT VARIABLES section:

.
.
OSSAUDIO_DEV
              The default audio output device, used by the OSSv4 output plugin.
.
.

My question is whether I need to set the $OSSAUDIO_DEV variable manually on my crontab environment, or if another variable that has to do with ALSA, Pulseaudio, or my dbus session has to be declared manually in my crontab file:

# *    *    *   *    *  Command_to_execute
# |    |    |    |   |       
# |    |    |    |    Day of the Week ( 0 - 6 ) ( Sunday = 0 )
# |    |    |    |
# |    |    |    Month ( 1 - 12 )
# |    |    |
# |    |    Day of Month ( 1 - 31 )
# |    |
# |    Hour ( 0 - 23 )
# |
# Min ( 0 - 59 )

SHELL=/bin/bash
HOME=/home/drjeff16
DISPLAY=:0.0
.
.
.
EDITOR="$(cat $HOME/.editor)"
isCron=1
.
.
.
1
  • Why don't you just try? I would definitely look for a missing environment variable; cron's environment is minimal. Commented May 15, 2021 at 18:53

2 Answers 2

0

Here's my boilerplate cron answer, I hope some of it helps.

Jobs run through cron, or at, or batch, aren't run in the same runtime environment that you have on your desktop. None of your PATH changes, or other environment variable settings are automatically propagated to your cron job. For example, there's no $DISPLAY, so GUI programs need special treatment (read man xhost).

One can set environment variables for all one's cron jobs in the crontab file Read man 5 crontab.

Look at the results of echo "=== set ===";set;echo "=== env ===";env | sort;echo "=== alias ===";alias in each of your environments.

Since the command part of the crontab line is, by default, interpreted by /bin/sh, which has a simpler syntax than /bin/bash, I recommend having command be a call to a bash script (executable, mounted, starts with7 #!/bin/bash) which sets up the environment, then calls the desired program.

0

You can try to define XDG. For example:

* * * * * XDG_RUNTIME_DIR=/run/user/$(id -u) /path/to/script

Sound started working for me. Do not forget to edit job timing (* * * * *) so it does not run every minute.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .