Script for alarm clock [Not working, need help]



First of all, the script I show you here is not working but I don't know if I'm doing something bad or I found a bug. This script is a part of a bigger script I'll use to transform my headless raspberry pi into a complete alarm clock. I used mocp during a week to test it without any problem (I usually use cmus but I need a music player that can run in background) but now that I want to make a script with it, it doesn't work. And I don't do anything more than usual. Once I met this bug, anything I do won't work anymore (this make me think it is a bug). I could reboot computer but uninstalling/reinstalling fix the bug and is faster.

The bug is "FATAL_ERROR: Can't receive value from the server!".

Here is the script :

# USAGE: ./
# DESCRIPTION: Met de le musique de plus en plus fort pendant 2min30 puis l'éteint, attend 5 minutes et enfin la remet encore plus fort pendant 2 minutes. Pour l'éteindre, en plus du pkill, utiliser mocp -x.
# OPTIONS: ---
# BUGS: ---
# NOTES: Utilise mocp pour la musique. pkill mocp au départ du script.
# AUTHOR: AdrienHorgnies (),
# COMPANY: Louvain-li-Nux
# VERSION: 1.0
# CREATED: 09/03/2014 16:00:45 CET


if [ $(ps -C mocp|wc -l) -eq 1 ];then
mocp --server #It clears the playlist so you do realize the alarm is ringing.
mocp --clear

mocp --append $music #--on shuffle,repeat --volume 50
mocp --on shuffle,repeat
mocp --volume 50
mocp --next
mocp --play
#This try to make you start the day with a random song each time. It toggles next because otherwise it would always starts with first music of the directory. It sets repeat option so it still works with only one music in the directory.

sleep 30s
mocp --volume +10
sleep 60s
mocp --volume +20
sleep 60s
mocp --pause

sleep 5m
mocp --volume +10
sleep 150s
mocp --exit #surrend to wake up.

Earlier versions worked but I didn't think I would need a version manager for something that simple :-s.

I would be thankful if you can help me in any way,


I can't see any obvious problem with your script. Your problem may be caused by some audio file you've recently added to your music directory rather than the script itself.

You don't tell us which version of MOC you are running but as of 2.5.0-beta2 the MOC server will log the reason for a fatal error to the system log (with selector user.err). I'm guessing that the RPi does not write the logs to media, but that's configurable in
/etc/syslog.conf. That would give you more information.

BTW, consider using pgrep(1) to test for a running server.