Using XFCE.
My crontab file…
0 08 * * * mpg123 /home/ion/TEMP/provata.mp3
0 20 * * * mpg123 /home/ion/TEMP/provata.mp3
mpg123 /home/ion/TEMP/provata.mp3 plays normally but crontab does not complete. Any suggestions will be appreciated.
Using XFCE.
My crontab file…
0 08 * * * mpg123 /home/ion/TEMP/provata.mp3
0 20 * * * mpg123 /home/ion/TEMP/provata.mp3
mpg123 /home/ion/TEMP/provata.mp3 plays normally but crontab does not complete. Any suggestions will be appreciated.
try /usr/bin/mpg123 instead and check if the owner of the crontab file is added to the usergroup audio and video.
Alternatively you could try to pipe the file from stdin cat path/to/file1.mp3 | mpg123 -
Which crontab file? Is it your user crontab, roots or the global crontab?
After tinkering around and stumbling upon this solution on stack overflow, the major problem is that crontab entries and other cronjobs are executed by crond in its own restrictive environment.
This solution addresses this limitation by using a local shell script that loads the users environments additionally that I simply placed in my home folder ~/audio-test.sh
#!/usr/bin/bash
XDG_RUNTIME_DIR=/run/user/`id -u` /usr/bin/mpg123 /path/to/file.mp3
Instead of editing the crontab via crontab -e I prefer it to use drop-in configuration files like /etc/cron.d/audio-test, that way the current user could be used instead of root
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=""
0 00 * * * username /path/to/script.sh
[ion@ion-desk ~]$ sudo usermod -a -G audio,video ion
My crontab…
04 15 * * * /usr/bin/mpg123 /home/ion/TEMP/provata.mp3
05 15 * * * /usr/bin/mpg123 /home/ion/TEMP/provata.mp3
No change.
User crontab.
Please check my latest post.
If you’ve got questions about that solution, feel free to ask.
I’m sorry, I don’t follow your explanation. Where does this file reside?
#!/usr/bin/bash
XDG_RUNTIME_DIR=/run/user/`id -u` /usr/bin/mpg123 /path/to/file.mp3
…and I don’t understand how I would deal with five different times. Sorry, it’s a bit above my ability. Shouldn’t crontab function the way it does in other operating systems? Simply?
I don’t have to use crontab if there is another alarm program that allows for several different alarm times.
I’ve simply created the shell script within my home folder, just for testing purposes.
You could place it within the same folder where the mp3 is stored.
By the way thanks for the speedy answer. I understand and i saved it as /home/ion/testalarm. It runs a test as expected. Now as for this file…
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=""
0 00 * * * username /path/to/script.sh
…for three alarms every day I would use..
0 08 0 0 0 ion /home/ion/testalarm
0 11 0 0 0 ion /home/ion/testalarm
0 16 0 0 0 ion /home/ion/testalarm
Am I on the right path? Somehow I think I got it wrong.
You really should save the shell script testalarm file as testalarm.sh and don’t forget to make it executable.
Additionally, if the alarm should be triggered at 8:00, 11:00 & 16:00h you could combine it this way in a single line.
0 08,11,16 * * * ion /home/ion/testalarm.sh
crontab.guru might help. 0 16 0 0 0 won’t work. The 3rd entry only accepts values 1-31 (for days), the 4th 1-12 (months) but the 5th entry for weekdays accepts 0, which would be sundays.
If you want to trigger this alarm only during the week, not saturdays and sundays, the entry would be
0 08,11,16 * * 1-5 ion /home/ion/testalarm.sh
To test I used..
1 12 * * * ion /home/ion/testalarm.sh
3 12 * * * ion /home/ion/testalarm.sh
That being 12 noon and one minute and three minutes of every day. It did not work.
What are the contents of the testalarm.sh and which file permission does it have ?
To check if the shell script works as intended, simply exectute it via ./testarlarm.sh
Additionally, just for testing an crontab entry such as
*/1 * * * * ion /home/ion/testalarm.sh
would execute the shell script every minute of the hour.
Why don’t you try a systemd timer+service ?
A timer like this (not tested)
[Unit]
Description=alarm
[Timer]
OnCalendar=*-*-* 08,20:00:00
Unit=alarm.service
[Install]
WantedBy=timers.target
edit: you can use systemctl status and journalctl for verification
Contents of testalarm.sh…
#!/usr/bin/bash
XDG_RUNTIME_DIR=/run/user/`id -u` /usr/bin/mpg123 /home/ion/TEMP/provata.mp3
it is executable and when run produces the wanted sound. Using crontab -e I modified it as you suggested…
/1 * * * * ion /home/ion/testalarm.sh
Still does not work.
Thanks for the suggestion. I am not familiar with systemd. I will try it if all else fails. But since crontab works under .rpm and .deb distros I think it should work here. I just switched from another distro, and if Endeavour is not reliable I think I will just move to something else. I believe it’s better to fix a problem as opposed to working around it.
I mentioned the systemd timer+service because it seems easier to diagnose problems ( it also works on most rpm/deb distros since they use systemd ).
As I’ve mentioned earlier what worked for me has been :
Additionally
That * in the front is a requirement, simply /1 doesn’t work.
Yes I corrected that.