Bash script Onion start problem omega 2
-
ahhh looks like i have to write my first bash script these days and also wanna include it with the start routine of the onion, but still have a problem....next one
here is the status:
...i can start the mp3 stream directly from the commandline with mpg123 http://.........mp3...stream => that works
- here the full bash script i putted in /usr/bin folder
#!/bin/ash
gpioctl dirin 0 gpioctl dirin 1 gpioctl dirin 2 gpioctl dirin 3 gpioctl dirin 6 gpioctl dirin 7 gpioctl dirin 8 gpioctl dirin 9 COUNTER=0 while [ $COUNTER -lt 100 ]; do
BUTTON0=$(gpioctl get 0 | grep Pin | cut -b 10)
BUTTON1=$(gpioctl get 1 | grep Pin | cut -b 10)
BUTTON2=$(gpioctl get 2 | grep Pin | cut -b 10)
BUTTON3=$(gpioctl get 3 | grep Pin | cut -b 10)
BUTTON7=$(gpioctl get 7 | grep Pin | cut -b 10)
BUTTON8=$(gpioctl get 8 | grep Pin | cut -b 10)
BUTTON9=$(gpioctl get 9 | grep Pin | cut -b 10)
if [ $BUTTON0 = 'H' ]; then
killall mpg123
echo starting radio mode
echo GROOVE SALAD
mpg123 http://ice3.somafm.com/groovesalad-256-mp3 &
fi
if [ $BUTTON1 = 'H' ]; then
killall mpg123
echo starting radio mode
echo SECRETAGENT
mpg123 http://ice1.somafm.com/secretagent-128-mp3 &
fi
if [ $BUTTON2 = 'H' ]; then
killall mpg123
echo starting radio mode
echo OE1
mpg123 http://mp3stream3.apasf.apa.at:8000 &
fi
if [ $BUTTON3 = 'H' ]; then
killall mpg123
echo starting radio mode
echo GROOVESALAD
mpg123 http://ice3.somafm.com/groovesalad-256-mp3 &
fi
if [ $BUTTON9 = 'H' ]; then
killall mpg123
echo starting radio mode
echo SECRETAGENT
mpg123 http://ice1.somafm.com/secretagent-128-mp3 &
fi
if [ $BUTTON8 = 'H' ]; then
killall mpg123
echo starting radio mode
echo OE1
mpg123 http://mp3stream3.apasf.apa.at:8000 &
fi
sleep 1
done
2nd The script is called from the file /etc/rc.local, so it starts when the Omega2 reboots:
/usr/bin/radio.sh & > /dev/null
exit 0
3rd the hardware (buttons) seems fine to me working, but how can i try the script now and test it?
Make the script executable by running the command: " chmod +x radio.sh "
execute the script by typing " ./radio.sh "
i am not sure, how to test my skript? without including it immediately
i hope you can help me with my weired post
ps omega onion firemware is up to date. i also did "oupgrade -force" in the commandline
-
@Christian-Munk i certainly agree your post is a bit strange. are you asking forum members to debug, if necessary, and test your script? the formatting of the script in your post makes it hard for me to understand.
-
Hello, i put the bashscript in my dropbox. here is the link
https://www.dropbox.com/sh/u3s8lqdn0f9g6u2/AACvfddIZcKHp-cJ98nmrnCPa?dl=0[link text](link url)
maybe you can try to start it.thx lg christian
-
@Christian-Munk the issue with me testing it is i need to have a working mpg123 client working on the omega2+ so i need to ask you how difficult is it to get that client operational on the omega2+ because i have never before used it, or even heard of it since i use youtube music to get my music feeds. is mpg123 a time consuming adventure?
thanks
-
just type
run opkg update
opkg install mpg123
thats it.
to listen the stream i connected a small usb soundcard on my onion (with a powered usb adapter)
-
@Douglas-Kryder and make sure you take the *.sh file from dropbox. It is my last upload and the streams should work
-
@Christian-Munk One little hint on avoiding some debugging....
if [ $BUTTON2 = 'H' ]; then
If the variable BUTTONn is null, you've got a problem. Wrap the variable and it's evaluation $ in double quotes so it at least evaluates to a null string, not a null.
if [ "$BUTTON2" = 'H' ]; then
take care!
Bill
-
THX for the info
i included that, reduced the script to the only necessary stuff and put in the radioV2.sh in my dropbox.
https://www.dropbox.com/s/k73t8k848zceg5b/radioV2.sh?dl=0[link text](link url)
here is the error i get now on the last line:
/usr/bin/radioV2.sh: line 56: syntax error: unexpected "done" (expecting "then")
Any Ideas what is the problem here?
-
@Christian-Munk
In general, first thing I always recommend is changing
/usr/bin/radio.sh & > /dev/null
to
/usr/bin/radio.sh & > /var/log.radio.log
Why would you throw away whatever the author of a script was trying to tell you.The technique to solve this and many problems in general is:
- copy the origin source to source.broken (or similar)
- remove a chunk of code, especially on of a group of similar segments.
- Try it.
- Save that version and go back to step 2 if it still fails.
I have found that having 2 windows open, one with vi chopping up the code and another executing the code allows you to undo the last delete +and examine it carefully.
Another thing that you can do, when if executes but not the way you want is the oldest(well second oldest after setting an address stop +from the front panel) add output statements like
echo "got to stage2" >> script.log
or
logger "stepping along count:$count:" #this goes to either the local syslog hopefully configured to save messages in /var/log or even +another system that can collect the messages if the target system cannot be accessed now (or later)Get rid of most (not all ) of the if..fi . This won't fix the problem but will allow you to get a better view of what remains.
-
GOT IT WORKING THX DENNIS
-
@Christian-Munk Please let us know the corrected version of your script too.
-
https://www.dropbox.com/s/3eriotijo0fvfxx/radio.sh?dl=0
yoooo here is the link , how it worked for me.