In my case I run crontab using current user session:
$ crontab -e
* * * * * /usr/bin/play -q /home/user/test/bell.wav
This makes a sound playing every minute.
First try using simpler commands.
If you want to configure alarm for different users, you could use crontab -e
from their terminal sessions. To switch to other user terminal session, use su username
command.
But, better, instead of using commands with parameters in crontab, use script and specify its path in crontab. Don't forget to chmod +x yourscriptpath
and also, don't forget to specify full paths to binaries and check your scripts by executing sh pathtoyour/script.sh
If you could run the next in terminal:
XDG_RUNTIME_DIR=/run/user/$(id -u) play -q /home/harun/Desktop/music.wav > alarmFile
crontab alarmFile
rm -f alarmFile
rm -f musicFile.txt
Then you could try to add it in your crontab file by crontab -e
command execution and by editing it:
15 7 * * * XDG_RUNTIME_DIR=/run/user/$(id -u) play -q /home/harun/Desktop/music.wav > /home/harum/alarmFile && /bin/rm -f /home/harun/alarmFile && /bin/rm -f /home/harum/musicFile.txt
To check if it works now, just replace 15 7
by * *
.
Script creation:
vim.tiny /home/harum/alarm.sh
#!/bin/bash
XDG_RUNTIME_DIR=/run/user/$(id -u) play -q /home/harun/Desktop/music.wav > /home/harum/alarmFile && /bin/rm -f /home/harun/alarmFile && /bin/rm -f /home/harum/musicFile.txt
Making script executable:
chmod +x /home/harum/alarm.sh
Adding script to crontab:
crontab -e
15 7 * * * /home/harum/alarm.sh
Finally, as one of commentators suggested, you could use XDG_RUNTIME_DIR
in your script by specifying the specific user directly (if you want to run your script as root but use other's user id in your script:
XDG_RUNTIME_DIR=/run/user/$(id yourSpecificUser | awk -F" " '{print $1}' | awk -F"(" '{print $1}' | awk -F"=" '{print $2}')
crontab -e
orsudo crontab -e
? Do you want to run this alarm only for one user or for each user that could be logged in?