1

I'm using my Raspberry Pi as a music server : I've installed MPD running under Archlinux ARM.

I'd like to set a cronjob that would check wether MPD has been active for a given period of time and if it's beeni inactive, safely shutdown the system by issuing a shutdown -h now command.

How can I check wether a daemon has been active or not in the last XXX minutes.

Thomas
  • 11
  • 2

1 Answers1

2

you may check if the program is running with pgrep -c mpd, that outputs 0 if no such program is found, otherwise 1 (or 2 or more).

please define "active" ?

ok, you want to know the status of the current song in mpd. the easiest way could be using python-mpd and a little bit of python scripting:

>>> status = client.status()
>>> status['state']
'play'        # or 'pause' or 'stop'

you may setup your python script to run at the regular intervals using cron and check the current mpd status. if it's playing, save the current time to some file, otherwise calculate the difference between the current time and the last saved playing time, if the difference exceeds your threshold, issue shutdown command.

lenik
  • 11,541
  • 1
  • 30
  • 37
  • By active, I mean that mpd outputs audio content. I'm looking for a way to check wether mpd has been outputting content for the last XXX minutes, for example. – Thomas May 07 '13 at 16:11
  • @Thomas see updated answer – lenik May 08 '13 at 15:33