Register
It is currently Wed Jul 23, 2014 5:39 pm

1 script for my usb-keypad


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Tue Nov 25, 2008 1:20 pm   

Joined: Tue Nov 25, 2008 12:58 pm
Posts: 2
Hi,

i need some help with writing a script that do this:

When i first start the script with "./switch-stations.sh" it runs the station_1 link and quit it self.
Run the script again it switch to the station_2 link and quit it self.

Code:
#!/bin/bash
# define the stations
station_1=$(mplayer .....)
station_2=$(mplayer .....)
#station_99=$(mplayer .....)



Thanks for helping me
sry for my broken english
Tiara


Top
 Profile  
 PostPosted: Tue Dec 02, 2008 6:29 am   

Joined: Mon Nov 17, 2008 7:25 am
Posts: 221
Well to start.

You shouldn't use the "execute in variable" method for this.

I would do something like this if you want to do this:
Code:
#!/bin/bash
# stations="space separated list with stations"
# Example below
stations="station1.com:8000 station2.com sub.domain.station3.com:9000"
for i in $stations; do
   mplayer $i
done


The way you're doing it will probably "work" but it's not the way it should be done and as you've experienced some iffy things happens :P

Executing something into a variable is useful when you need to modify the output of another program (or just need the output for some reason).
Example:
Code:
#!/bin/bash
hello="Hello world :)"
hello=$(echo $hello | replace 'Hello' 'Goodbye')
echo $hello


More advanced examples can be found on google, but you can pretty much do anything that just spits output to standard output (stdout) :)

Best regards
Fredrik Eriksson

edit: Oh sry, I think i missunderstood you. You want a script that starts playing a specific station when you press a specific button?
Code:
#!/bin/bash
case $1 in
    1)
      mplayer station.com
    ;;
    2)
      mplayer station2.com
    ;;
esac

Maybe something like that would be better? when you run that you'll just pass it like this: ./script.sh 1
That will run "mplayer station.com", if it would have been a 2 you might guess what it'd do :)


Top
 Profile  
 PostPosted: Wed Dec 03, 2008 1:16 pm   

Joined: Tue Nov 25, 2008 12:58 pm
Posts: 2
HI fredrik.eriksson

Thanks for reply, but i found this script on a debian forum (http://nopaste.debianforum.de/16803):

Code:
#!/bin/bash

# One-Touch Version 0.1
# Contact Homeless1: At this Time only over PM at debianforum.de Forum (You can write your Question in German or English)

# Copyright (C) 2008 Homeless1
# This program is free software;
# you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation;
# either version 3 of the License, or (at your option) any later version.

# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.

# You should have received a copy of the GNU General Public License along with this program;
# if not, see <http://www.gnu.org/licenses/>.

#########################################
# Setting up Path to File one-touch.log and Playlist
CHECK_PATH=/home/user
PLAYLIST_PATH=/home/user/playlists

############################
# Check if File one-touch.log exists.

if [ "$(cat $CHECK_PATH/one-touch.log)" = "" ]; then
echo "Create Station Checklist" # Debug Output
echo "0" > $CHECK_PATH/one-touch.log
exit
fi

###################
# Activate Station 0

if [ "$(cat $CHECK_PATH/one-touch.log)" = "0" ]; then
echo "Activate Station 0" # Debug Output
pls-handler.sh $PLAYLIST_PATH/station-0.pls
echo "1" > $CHECK_PATH/one-touch.log
sleep 2
exit
fi

###################
# Activate Station 1

if [ "$(cat $CHECK_PATH/one-touch.log)" = "1" ]; then
echo "Activate Station 1" # Debug Output
pls-handler.sh $PLAYLIST_PATH/station-1.pls
echo "2" > $CHECK_PATH/one-touch.log
sleep 2
exit
fi

###################
# Activate Station 2
if [ "$(cat $CHECK_PATH/one-touch.log)" = "2" ]; then
echo "Activate Station 2" # Debug Output
pls-handler.sh $PLAYLIST_PATH/station-2.pls
echo "3" > $CHECK_PATH/one-touch.log
sleep 2
exit
fi
     
##############
# Stop the MPD
if [ "$(cat $CHECK_PATH/one-touch.log)" = "3" ]; then
echo "Stop the Mediaplayer Daemon" # Debug Output
mpc stop
echo "0" > $CHECK_PATH/one-touch.log
sleep 2
exit
fi


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP