I have been at this for a month now. New to programming. Trying to run a schedule for wav files to execute. Using Raspberry Pi 3 and Raspbian Stretch. My cron.d file called 'BellCron' is as follows:

/5 * * * * pi /home/pi/CronJobs/BellsCron.sh

Applied chmod +x to the BellsCron.sh file.

It is a file that executes a second file, 'playAngelus.py'. When I execute 'BellsCron.sh' at the command line it works fine.

The 'BellsCron.sh file looks like this:

#!/usr/bin/env python

sudo -u pi python /home/pi/CronJobs/playAngelus.py

The 'playAngelus.py' file looks like this:

#!/user/bin/env python

import pygame

import time





I have also run a text file from the same cron.d file that is giving me the time in a file every 2 minutes, so I know it is running cron. But, the sound file will not work using cron. I accept that the error is mine. I have tried every configuration I can find on the web. I would be most appreciative if someone would help me to write the script I need to execute a wav file in my home directory, /home/pi/Music/Angelus.wav, using cron.d or crontab.

  • You shouldn't ever need to sudo -u pi …, as that's just reverting your cron job back to the default Raspbian user.
    – scruss
    Commented Nov 15, 2017 at 23:29

4 Answers 4



sudo -u pi python /home/pi/CronJobs/playAngelus.py

I think 'python' should be replaced with full path of python executable, something like: /usr/bin/python

So your code should look something like: sudo -u pi /usr/bin/python /home/pi/CronJobs/playAngelus.py

Hope this solves your problem.

  • 1
    I was sooo close. After what seemed like 50 combinations of entries, you showed me the 51st, and the right one at that . Thank you for your help.
    – fjco
    Commented Nov 14, 2017 at 18:59

Why not simply play the wav file directly from the cron job ?

*/5 * * * * /usr/bin/aplay /home/pi/Music/Angelus.wav
  • Tried this, but without success, even after reboot. But the solution was found. Thanks for your help.
    – fjco
    Commented Nov 14, 2017 at 18:56
  • This works on my Pi3
    – CoderMike
    Commented Nov 14, 2017 at 19:01
  • I'd be interested to see what your log states : 'grep CRON /var/log/syslog'
    – CoderMike
    Commented Nov 14, 2017 at 20:45

If you're running a graphical login, audio depends on X display access. cron jobs don't have the right environment variables set. I had a setup that produced an hourly chime, and this is what worked.

Install play, the sox audio player:

sudo apt install sox libsox-fmt-all

Edit your crontab the recommended way:

crontab -e

Add this line, save and exit:

*/5 * * * * export DISPLAY=:0 && /usr/bin/play -q /home/pi/Music/Angelus.wav
  • Tried this, but to no avail. However, the solution was found. Thanks for your help.
    – fjco
    Commented Nov 14, 2017 at 18:55

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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.