Simple bash script.

Code junkies hangout here

Moderators: ChrisThornett, LXF moderators

Simple bash script.

Postby Xraynorm » Sun Jun 11, 2006 8:56 am

Hello

I've built an wireless mp3 player out of an old compter using DSLiinux. When it boots it runs the command :-

xmms http://192.168.0.3:9000/stream.mp3

This connects to my server and plays my mp3s.

I would like to write a script that re executes the above line if it fails to connect.

This will enable me to turn off the main sever at night, and when I turn it back on the media player should reconnect automatically.

Any help would be greatfully received
Xraynorm
LXF regular
 
Posts: 122
Joined: Tue Feb 07, 2006 9:36 pm

RE: Simple bash script.

Postby jmeads » Sun Jun 11, 2006 9:47 am

you just need to wrap it in a while loop, something like

while 1
command here
end

ugly, but it should do the trick, see man bash for more info
User avatar
jmeads
 
Posts: 1
Joined: Wed Nov 30, 2005 12:21 pm

Re: RE: Simple bash script.

Postby Steogede » Sun Jun 11, 2006 12:43 pm

jmeads wrote:you just need to wrap it in a while loop, something like

while 1
command here
end

ugly, but it should do the trick, see man bash for more info


You probably want to don't want it to continually try to connect. Shove a sleep command in there to give it a breather. e.g.

while true; do
command here;
sleep 2m;
done;

However that probably isn't what you want. Re-executing 'xmms http://192.168.0.3:9000/stream.mp3' ever time it fails to connect will leave you with lots of copies of xmms running. When XMMS fails to connect, it doesn't shut down automatically. Also because XMMS doesn't shutdown when it loses/fails to get a connection, the above would only run the command once; until you manually closed xmms.

It seems from searching the net, it seems the best option is probably to run a stream server on the local machine. This server would relay the other server when it gets a connection and play a local file when it can't get a connection. Try searching for stream relay.

One more thing, if you are turning the server off at night, why would you want to keep the client on?

You may also want to see if you can find a command line player that will exit if it loses/fails to get a connection - mpg321 might be upto the job.
Steogede
LXF regular
 
Posts: 146
Joined: Thu May 04, 2006 5:39 pm


Return to Programming

Who is online

Users browsing this forum: No registered users and 2 guests

cron