-1

here my system info:

$ uname -a
Linux rp4 6.6.51+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.6.51-1+rpt1 (2024-09-26) aarch64 GNU/Linux

All these lines are working directly from command line on RPi4.

18 21 * * * /usr/bin/play /home/user/1.mp3 >/dev/null 2>&1
19 21 * * * /usr/bin/play /home/user/1.mp3
20 21 * * * sh /home/user/playlist.sh

Here is the executable script playlist.sh:

#!/usr/bin/env bash

/usr/bin/play "/home/user/5.m3u"

This one is working

30 21 * * * touch test.txt

What do I do wrong? Thank you :)

goldilocks U DA MAN! By using your hint to redirect the output to a file (I am so stupid not to think about it my self). I got these 3 lines in the file:

couldn't open play stream: Unknown error 524 /usr/bin/play FAIL ao: Could not find a default ao driver /usr/bin/play FAIL sox: Sorry, there is no default audio device configured

By using aplay -l I found my default device. Which is bcm2835 Headphones

$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: vc4hdmi0 [vc4-hdmi-0], device 0: MAI PCM i2s-hifi-0 [MAI PCM i2s-hifi-0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: vc4hdmi1 [vc4-hdmi-1], device 0: MAI PCM i2s-hifi-0 [MAI PCM i2s-hifi-0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: Headphones [bcm2835 Headphones], device 0: bcm2835 Headphones [bcm2835 Headphones]
  Subdevices: 8/8

Here I found how to set a default device with SOX: https://linux.die.net/man/1/sox

set AUDIODEV=hw:2 in my case export AUDIODEV=hw:2

Here is my final script:

#!/usr/bin/env bash

export AUDIODEV=hw:2

/usr/bin/play "/home/user/5.m3u"

2
  • your question belongs at unix.stackexchange.com/questions
    – jsotola
    Commented Oct 1 at 5:13
  • 1
    Maybe you should explain what it is you're trying to do. Your command sequence doesn't make much sense to me.
    – Seamus
    Commented Oct 1 at 6:41

1 Answer 1

2

Chances are cron is working, it's the command that's not -- because it does not automatically have access to the sound system when run this way.

Instead of discarding any possible output, you should write it to a file somewhere in case there's an informative error, etc.:

18 21 * * * /usr/bin/play /home/user/1.mp3 >/var/log/cron-play.txt 2>&1

If that's a user cron tab (and not the system one), you'll want a different log path since that requires root privilleges. /tmp is a good place for that since anyone can use it, but it all gets deleted on reboot.

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.