Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: I need help correcting a bash script

  1. #1
    Join Date
    Feb 2010
    Location
    24/6 in bed
    Beans
    36
    Distro
    Ubuntu 10.04 Lucid Lynx

    I need help correcting a bash script

    Code:
    1. JK Says: Here is a one-liner bash function that will allow you to stream any iheartradio station by typing: iheartradio function iheartradio { mplayer -quiet $(wget -O – -q “http://p2.$1.ccomrcdn.com/player/player_dispatcher.html?section=radio&action=listen_live” | sed -n “s|.*primary_location=\”\(rtmp://[^\"]*\)\”.*|\1|p”) -novideo >& /dev/null; }
    Hello, i hope i'm posting in the right section. For some reason i can't really understand scripting language. Could anyone please make this work for me?
    I'll try to explain what i'm doing here.

    There's this flash radio site, and i want to access it from the terminal through a simple command.
    The rtmp:// stream changes every hour or something like that. This stream can always be found into this xml page http://p2.wrzx-fm.ccomrcdn.com/player/player_dispatcher.html?section=radio&action=listen _live

    Code:
    <stream id="909" primary_location="rtmp://cp21575.live.edgefcs.net/live/Ind_IN_WRZX-FM_OR@s7701?auth=daEbvahaVbMbyczbEd2bCdRcIbtd9dQaScm-bot39e-4q-ML4V7_9opFFom4GBvmytAq&aifp=1234&CHANNELID=909&CPROG=_&MARKET=INDIANAPOLIS-IN&REQUESTOR=WRZX-FM&SERVER_NAME=p2.wrzx-fm.ccomrcdn.com&SITE_ID=2005&STATION_ID=WRZX-FM&MNM=2&TYPEOFPLAY=0" backup_location=""/>
    the command that plays fine the radio in the terminal is: mplayer "rtmp://url" -novideo
    so if it updates, i have to open the xml page again and again and copy the rtmp link to play.

    aparently this guy figured out this script that should grab the rtmp url and run it in mplayer through a single command, but i'm an idiot and have no knowledge why it's not working

    what i do know is that i need to put #!/bin/bash line at the beginning of my script and that i need to make it executable in order to actually run it, but it's not working

    here's my script:
    (i have replaced his $1 from the script line with wrzx-fm because that's the radio's name btw)

    Code:
    #!/bin/bash
    function iheartradio { mplayer -quiet $(wget -O – -q “http://p2.wrzx-fm.ccomrcdn.com/player/player_dispatcher.html?section=radio&action=listen_live” | sed -n “s|.*primary_location=\”\(rtmp://[^\"]*\)\”.*|\1|p”) -novideo >& /dev/null; }
    Code:
    tzily@PC:~/Desktop$ chmod u+x iheartradio.sh
    tzily@PC:~/Desktop$
    ok, and now to run the thing:

    Code:
    tzily@PC:~/Desktop$ iheartradio
    iheartradio: command not found
    tzily@PC:~/Desktop$ iheartradio.sh
    iheartradio.sh: command not found
    tzily@PC:~/Desktop$ ./iheartradio.sh
    tzily@PC:~/Desktop$ /.iheartradio.sh
    bash: /.iheartradio.sh: No such file or directory
    tzily@PC:~/Desktop$ .iheartradio.sh
    .iheartradio.sh: command not found
    tzily@PC:~/Desktop$ '/home/tzily/Desktop/iheartradio.sh'
    tzily@PC:~/Desktop$ sudo iheartradio.sh
    [sudo] password for tzily: 
    sudo: iheartradio.sh: command not found
    tzily@PC:~/Desktop$
    I'm trying hard to run it, but i assume the script needs something...
    this might look pathetic for some experienced fellows around here, but i'm new to this and if i don't get it right, i can't sleep tonight please someone correct and test this for me. Please...
    Last edited by tzily; August 20th, 2011 at 01:35 PM.

  2. #2
    Join Date
    Jan 2009
    Location
    Flanders
    Beans
    Hidden!

    Re: I need help correcting a bash script

    First, put your scripts in CODE tags, not QUOTE tags. It's a pita to change all the quotes to ascii chars.

    Second, if you put it in a script, you don't need to create a function, it's one of of both that you have to do. If you do both, the script will only create a function and won't execute that function.

    And now I'm trying to split it up in parts and see why it's not working.

    EDIT

    note to self: - signs also change
    2nd note to self, the url is http://p2.$1.ccomrcdn.com/player/player_dispatcher.html?section=radio&action=listen _live without the space before _live

    It works

    After changing those quotes, --signs and removing the space in the URL, it just works (and off course not using a function and a script together).
    Last edited by sanderd17; August 20th, 2011 at 12:50 PM.

  3. #3
    Join Date
    Feb 2010
    Location
    24/6 in bed
    Beans
    36
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: I need help correcting a bash script

    what signs ?
    btw it seems the site auto added the space between listen and _live
    is this the working script ?

    Code:
    #!/bin/bash
    { mplayer -quiet $(wget -O – -q  “http://p2.$1.ccomrcdn.com/player/player_dispatcher.html?section=radio&action=listen_live” | sed -n “s|.*primary_location=\”\(rtmp://[^\"]*\)\”.*|\1|p”)  -novideo >& /dev/null; }
    Last edited by tzily; August 23rd, 2011 at 07:25 AM.

  4. #4
    Join Date
    Feb 2010
    Location
    24/6 in bed
    Beans
    36
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: I need help correcting a bash script

    Code:
    PC:~/Desktop$ ./iheartradio.sh
    ./iheartradio.sh: line 2: p”: command not found
    ./iheartradio.sh: line 2: .*primary_location=”(rtmp://[^"]*)”.*: No such file or directory
    ./iheartradio.sh: line 2: 1: command not found
    sed: -e expression #1, char 1: unknown command: `�'
    tzily@PC:~/Desktop$
    Last edited by tzily; August 20th, 2011 at 01:08 PM.

  5. #5
    Join Date
    Jan 2009
    Location
    Flanders
    Beans
    Hidden!

    Re: I need help correcting a bash script

    you need to change the italic quotes to normal quotes. If you type something a word processor, or in this site, they automatically change the quotes to make it look better.

    So not these quotes : “quote”

    but these:

    Code:
    "quote"
    Apart from the quote, the minus-sign also changed into a bit longer minus (after the wget command, change it back to a normal minus) and you have found that space issue.
    Last edited by sanderd17; August 20th, 2011 at 01:18 PM.

  6. #6
    Join Date
    Oct 2010
    Beans
    316

    Re: I need help correcting a bash script

    Quote Originally Posted by sanderd17 View Post
    you need to change the italic quotes to normal quotes. If you type something a word processor, or in this site, they automatically change the quotes to make it look better.

    So not these quotes : “quote”

    but these:

    Code:
    "quote"
    Apart from the quote, the minus-sign also changed into a bit longer minus (after the wget command, change it back to a normal minus) and you have found that space issue.
    IIRC, there is no difference between directed quotation marks and straight ones (i.e it's the same ASCII char code). Copying and pasting between programs that display quotation marks in a more readable manner and those that don't shouldn't be an issue.
    Note: that isn't the case with the backtick(`) and the apostrophe(').

  7. #7
    Join Date
    Jan 2009
    Location
    Flanders
    Beans
    Hidden!

    Re: I need help correcting a bash script

    Quote Originally Posted by .... View Post
    IIRC, there is no difference between directed quotation marks and straight ones (i.e it's the same ASCII char code). Copying and pasting between programs that display quotation marks in a more readable manner and those that don't shouldn't be an issue.
    Note: that isn't the case with the backtick(`) and the apostrophe(').
    There is a difference in this case. If you check out the HTML code, you will see that some quotes are noted as &quot; and others as &# 8220; (without the space off course, but there is no bloody way to type it otherwise).

  8. #8
    Join Date
    Feb 2010
    Location
    24/6 in bed
    Beans
    36
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: I need help correcting a bash script

    Quote Originally Posted by sanderd17 View Post
    you need to change the italic quotes to normal quotes. If you type something a word processor, or in this site, they automatically change the quotes to make it look better.

    So not these quotes : “quote”

    but these:

    Code:
    "quote"
    Apart from the quote, the minus-sign also changed into a bit longer minus (after the wget command, change it back to a normal minus) and you have found that space issue.

    allright so the new script is

    Code:
    #!/bin/bash
    { mplayer -quiet $(wget -O - -q  “http://p2.$1.ccomrcdn.com/player/player_dispatcher.html?section=radio&action=listen_live” | sed -n “s|.*primary_location=\”\(rtmp://[^\"]*\)\”.*|\1|p”)  -novideo >& /dev/null; }
    or

    Code:
    #!/bin/bash
    { mplayer -quiet $(wget -O - -q  “http://p2.wrzx-fm.ccomrcdn.com/player/player_dispatcher.html?section=radio&action=listen_live” | sed -n “s|.*primary_location=\”\(rtmp://[^\"]*\)\”.*|\1|p”)  -novideo >& /dev/null; }
    and output still fails on both:

    Code:
    PC:~/Desktop$ bash
    PC:~/Desktop$ ./iheartradio
    ./iheartradio: line 2: .*primary_location=”(rtmp://[^"]*)”.*: No such file or directory
    ./iheartradio: line 2: p”: command not found
    ./iheartradio: line 2: 1: command not found
    sed: -e expression #1, char 1: unknown command: `�'
    PC:~/Desktop$
    i'm too dumb for this, but i think the xml page linking to the rtmp url differs or something

    does the radio actually play for you after running the script ? :O
    Last edited by tzily; August 20th, 2011 at 01:53 PM.

  9. #9
    Join Date
    Jan 2009
    Location
    Flanders
    Beans
    Hidden!

    Re: I need help correcting a bash script

    All those errors still say that you use wrong quotes. Please change the quotes by straight ones.

  10. #10
    Join Date
    Feb 2010
    Location
    24/6 in bed
    Beans
    36
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: I need help correcting a bash script

    oh you meant these quotes " "

    ok then

    the colors in gedit actually changed after replacing all "
    Code:
    #!/bin/bash
    { mplayer -quiet $(wget -O - -q  "http://p2.wrzx-fm.ccomrcdn.com/player/player_dispatcher.html?section=radio&action=listen_live" | sed -n "s|.*primary_location=\"\(rtmp://[^\"]*\)\".*|\1|p")  -novideo >& /dev/null; }
    output is null

    Code:
    PC:~/Desktop$ ./iheartradio.sh
    tzily@PC:~/Desktop$

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •