1

A little more than a year ago I wrote a notifier app. (on Ubuntu 16.04.7) which played some audio with paplay and then put up a yad window with the text of the notification. This could be run either from command line or from cron. Recently I installed Ubuntu 20.04.3 and found that running from command line still works but running from cron doesn't. I have a bin directory below my home directory where the script (remind.sh) is kept. The pared down version of remind.sh is the following. Note that when I run from cron I get no audio indication the script has run but the trace.txt file gets updated and yad produces a window.

#!/bin/bash
# reminder script called from either
#           1. cron or
#           2. directly from shell to pop-up or
#           3. gidday.sh
# produces a 'yad' window with a picture and message in it.

/usr/bin/paplay /home/gary/sounds/marimba.ogg

# trace the run
d=`date`
echo "done -- "$d >> trace.txt

# now put out the window
#
#/usr/bin/yad --borders=50 --scroll --image=/home/gary/Pictures/shrunk-pictures/${ar[$t]} --title="${ar[$t]}" --text-align=center --mouse --width=800 --height=400 --text='<span font="20">'"$txt"'</span>' 2>/dev/null

Sorry, I should have provided the following in my original post. The line in crontab that fires off the remind1.sh script is:

36 13 30 aug * export DISPLAY=:0 && export MESSG="get movies from lib" && /home/gary/bin/remind1.sh

As I said before, this all ran perfectly fine in Ubuntu 16.04. And it still doesn't explain why the paplay command doesn't run but the (uncommented) yad command does.

2
  • Sorry, I should have provided the following in my original post. Aug 31, 2021 at 14:37
  • Not sure I'm doing this right but, does anyone have any idea/input as to why paplay doesn't run in Ubuntu 20 but works fine in Ubuntu 16 ?? Sep 2, 2021 at 15:13

2 Answers 2

1

Jobs run through cron, or systemd startup scripts aren't run in the same runtime environment that you have on your desktop. systemd startup scripts are run as root. None of your PATH changes, or other environment variable settings from your ~/.bashrc 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 "=== id ===";id;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 with #!/bin/bash) which sets up the environment, then calls the desired program.

2
  • Comments are designed for US to ask YOU questions about your Question. You should Edit your question to add information. By updating your Question, and using the formatting buttons, you make all the information available to new readers. People shouldn't have to read a long series of comments to get the whole story.
    – waltinator
    Aug 31, 2021 at 16:31
  • Has anyone got any idea why paplay doesn't run in my script on Ubuntu 20.04 but runs fine on Ubuntu 16.04 ?? And to address a comment in the original response, the command part of the crontab line may be interpreted by /bin/sh but the call is being made to a bash script. Sep 8, 2021 at 15:37
0

You should check output of

env|grep -i runt

For me it was XDG_RUNTIME_DIR=/run/user/1000
And then put it in environment of crontab job like so:

* * * * * export XDG_RUNTIME_DIR=/run/user/1000 && paplay sound.wav

You must log in to answer this question.

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