3

Goal:
- boot the rpi and for it to play an mp3 continuously

What I did:
- I autologin by editing /etc/inittab in the normal way
- I run my commands by editing ~/.bash_profile and adding mpg321 mymusic.mp3

The problem: the rpi boots, logs in the user, and plays the mp3. All good. But when I log in again via ssh, it runs the script again which plays the mp3 again, etc. I only want it to do that once.

I know I can have two users for this scenario, but I want to keep it simple and use one. Please help me do that?

0

It might be easier to use cron to schedule the task instead.

Open the cron task list in the default text editor:

crontab -e

Add a line at the bottom to run the task after a reboot:

@reboot mpg321 mymusic.mp3

Save the file and exit the text editor.

cron should now run the command line once at reboot as root. Note you may need to use an absolute path to mymusic.mp3, e.g. /home/pi/mymusic.mp3

| improve this answer | |
  • Works well, and only once! If I want to stop this task BTW, how do I do it while I'm logged in via ssh? – mrpi Oct 15 '13 at 9:13
  • @mrpi The easiest way would probably be to run sudo killall mpg321 – PiBorg Oct 15 '13 at 10:23
0

You could use "who" to know if you are already logged in:

if [ `who | grep "$LOGNAME" | wc -l` -eq 0 ]
then
    mpg321 mymusic.mp3
fi
| improve this answer | |
0

Add in an if statement to check to see whether mpg321 is already running. There are a whole bunch of ways to do this. First way that comes to mind is this -
pidof mpg321 | wc -l

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.