LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-26-2005, 08:58 AM   #61
infinity42
Member
 
Registered: Apr 2005
Location: England
Distribution: Gentoo
Posts: 142

Rep: Reputation: 16

You may have to, as filenames can be a problem in shell scripts. You could try escaping the parenthesis thusly:
Code:
echo $filename|sed -e 's/(/\\(/g' -e 's/)/\\)/g'
So
Code:
cat $PL_FILE2|awk '! /'"$filename"'$/ {print $L}'>$PL_FILE2
would become
Code:
cat $PL_FILE2|awk '! /'"$(echo $filename|sed -e 's/(/\\(/g' -e 's/)/\\)/g')"'$/ {print $L}'>$PL_FILE2
Not confident as to whether it will work or not, but it's worth a try.
 
Old 10-04-2005, 10:12 AM   #62
windisch
Member
 
Registered: Nov 2004
Location: Gahanna, Ohio, USA
Distribution: Fedora 9
Posts: 158

Original Poster
Rep: Reputation: 30
Huh, I never got the email about you replying. I'm sorry about that. I was trying to figure it out myself and was going to post my progress. I tried out your solution and it seems to work. Let me check and see if it works with brackets. If it doesn't work with brackets, I will rename the files. Thanks again for your help. I've found another little glitch, but I'll see if I can get it without bothering you.
 
Old 10-06-2005, 01:11 PM   #63
windisch
Member
 
Registered: Nov 2004
Location: Gahanna, Ohio, USA
Distribution: Fedora 9
Posts: 158

Original Poster
Rep: Reputation: 30
I'm not having a problem that it seems to be removing muliple songs after playing one. I've seen it have 10 or so songs queued and after the song is removed, it detects that the request file is empty and goes to the previous queue.

Edit:

When I revert your awk line back to the original, it does not seem to have this problem

Here's the entire code, because I've added a few things myself, not sure if it's my fault.


Code:
#!/bin/bash
process=sc_trans_linux  ###Process name entered into variable###
t=`pidof $process`      ###Grabs PID and enters it into variable###
echo $t
PL_FILE='MythMusic.temp'
PL_FILE2='MythMusic.alw'
REQ_FILE='/var/www/html/shoutcast/request.alw'
LOG_FILE='/home/draco/shoutcast/transcode/sc_trans.log'
QUE_FILE='request_queue.alw'
curfile="NON" #Just incase it doesn't get set on the first pass
tail -f --lines=1 $LOG_FILE $REQ_FILE|while read line;do
        if [ "$line" = "==> $REQ_FILE <==" ];then
                curfile="REQ"
        fi
        if [ "$line" = "==> $LOG_FILE <==" ];then
                curfile="LOG"
        fi
        if [ ! -z "`echo $line|sed 's/.*==>.*<==.*//'`" ];then
                if [ ! -f $PL_FILE ];then     #Will Ignore Removing Songs If Default List Is Loaded
                        echo "Ignoring Log"
                        if [ $curfile = "LOG" ];then
                                cmd=$(echo $line|sed 's/.*\[\(.*\)\].*/\1/')
                                msg=$(echo $line|sed 's/.*\] \(.*\)/\1/')
                                if [ $cmd = "DECODE" ];then
                                        filename=$(echo $line|sed 's/.*\] Opened \(.*\)/\1/')
                                        echo 'DECODE: '$filename
                                fi
                                if [ $cmd = "MAIN" ];then
                                        filename=""
                                        echo $filename
                                fi
                        fi

                else
                        if [ $curfile = "LOG" ];then
                                cmd=$(echo $line|sed 's/.*\[\(.*\)\].*/\1/')
                                msg=$(echo $line|sed 's/.*\] \(.*\)/\1/')
                                if [ $cmd = "DECODE" ];then
                                        filename=$(echo $line|sed 's/.*\] Opened \(.*\)/\1/')
                                        echo 'DECODE: '$filename
                                fi
                                if [ "$cmd" = "MAIN" -a "$msg" = "Title Updated" ];then
                                        if [ ! -z "$filename" ];then
                                                echo "Requested Song $filename Has Been Played.  Removing From Playlist."
                                                #cat $PL_FILE2|awk '! /'"$filename"'$/ {print $L}'>$PL_FILE2
                                                cat $PL_FILE2|awk '! /'"$(echo $filename|sed -e 's/(/\\(/g' -e 's/)/\\)/g')"'$/ {print $L}'>$PL_FILE2
                                                if [ `wc -c $PL_FILE2|sed 's/ .*//'` -eq 0 ];then
                                                        echo "Empty"
                                                else
                                                        kill -s USR1 $t
                                                        cp MythMusic.alw /var/www/html/shoutcast/MythMusic.alw
                                                fi
                                                filename=""
                                                #If there is a request queue, act on the queue
                                                if [ -f $QUE_FILE ];then
                                                        if [ ! -f $PL_FILE ];then
                                                                echo "CREATE: $PL_FILE2"
                                                                mv $PL_FILE2 $PL_FILE
                                                                touch $PL_FILE2
                                                                chmod 666 $PL_FILE2
                                                                kill -s USR2 $t #Should this be below the loop?
                                                        fi
                                                        cat $QUE_FILE|while read line;do
                                                                echo $line >> $PL_FILE2
                                                                echo "Adding $line To Request List"
                                                        done
                                                        kill -s USR1 $t
                                                        cp MythMusic.alw /var/www/html/shoutcast/MythMusic.alw
                                                        rm -f $QUE_FILE
                                                fi
                                        fi
                                fi
                        fi
                fi
                if [ $curfile = "REQ" ];then
                        echo "REQUEST: $line"
                        echo "Filename: $filename"
                        if [ ! -z "$filename" ];then
                                echo 'Decoding In progress, adding request to queue.'
                                echo $line>>$QUE_FILE
                        else
                                if [ ! -f $PL_FILE ];then
                                        #If it doesn't exist then create an empty file using touch and add song to list
                                        echo "CREATE: $PL_FILE2"
                                        mv $PL_FILE2 $PL_FILE
                                        touch $PL_FILE2
                                        chmod 666 $PL_FILE2
                                        echo $line >> $PL_FILE2
                                        kill -s USR2 $t
                                        kill -s USR1 $t
                                        cp MythMusic.alw /var/www/html/shoutcast/MythMusic.alw
                                else
                                        echo "Adding $line To Request List"
                                        echo $line >> $PL_FILE2  #Adds To Currently Plaing Request List
                                        kill -s USR1 $t
                                        cp MythMusic.alw /var/www/html/shoutcast/MythMusic.alw
                                fi
                        fi
                fi
        fi
        if [ `wc -c $PL_FILE2|sed 's/ .*//'` -eq 0 ];then
                echo "Request Playlist Is Empty, Reverting To Default Playlist"
                mv $PL_FILE $PL_FILE2
                kill -s USR2 $t
                kill -s USR1 $t
                rm /var/www/html/shoutcast/MythMusic.alw
        fi
done

Last edited by windisch; 10-06-2005 at 02:13 PM.
 
Old 10-06-2005, 02:20 PM   #64
infinity42
Member
 
Registered: Apr 2005
Location: England
Distribution: Gentoo
Posts: 142

Rep: Reputation: 16
I'm not sure I quite understand the problem; I have forgotten some of the specifics of what we were doing (i've a rusty brain ). If you could just post what line is changing to/from to create the problem, and a little clearer explaination of it I'll be happy to help
 
Old 10-06-2005, 02:40 PM   #65
windisch
Member
 
Registered: Nov 2004
Location: Gahanna, Ohio, USA
Distribution: Fedora 9
Posts: 158

Original Poster
Rep: Reputation: 30
I'm sorry, I know its been a while.

This section here. This is the part that removes a song once it is played from my request list. You changed this so it would detect a parentheses in a song title, but now it's clearing all songs after one is played, and I'm not sure why. If I uncomment the old line and comment the new one, it plays all of the files, except parentheses. Like I mentioned before, if thats too much of a problem, I will remove the parentheses.

Code:
if [ "$cmd" = "MAIN" -a "$msg" = "Title Updated" ];then
                                        if [ ! -z "$filename" ];then
                                                echo "Requested Song $filename Has Been Played.  Removing From Playlist."
                                                #cat $PL_FILE2|awk '! /'"$filename"'$/ {print $L}'>$PL_FILE2
                                                cat $PL_FILE2|awk '! /'"$(echo $filename|sed -e 's/(/\\(/g' -e 's/)/\\)/g')"'$/ {print $L}'>$PL_FILE2
                                                if [ `wc -c $PL_FILE2|sed 's/ .*//'` -eq 0 ];then
                                                        echo "Empty"
                                                else
                                                        kill -s USR1 $t
                                                        cp MythMusic.alw /var/www/html/shoutcast/MythMusic.alw
                                                fi
                                                filename=""
                                                #If there is a request queue, act on the queue
 
Old 10-06-2005, 05:31 PM   #66
infinity42
Member
 
Registered: Apr 2005
Location: England
Distribution: Gentoo
Posts: 142

Rep: Reputation: 16
Hmm, I think the parenthesis may be more trouble than they are worth. I usually try to stick to [A-Z], [a-z], [0-9], and [_-] in filenames, as they cause so much less hassle in the long run. I'm sure there is a way round it, but I'm afraid I don't know it

Sorry I can't help with that.
 
Old 10-07-2005, 07:26 AM   #67
windisch
Member
 
Registered: Nov 2004
Location: Gahanna, Ohio, USA
Distribution: Fedora 9
Posts: 158

Original Poster
Rep: Reputation: 30
No problem, you've done more then enough work. I will come up with a way to rename all of those songs.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 06:32 PM
creating shell script programming using KNOPPIX.. help cinderella Linux - Newbie 4 12-20-2004 08:12 PM
Creating a shell script to run Java program paultaylor Programming 7 11-12-2004 04:11 PM
creating shell script that executes as root regardless of who runs the script? m3kgt Linux - General 13 06-04-2004 11:23 PM
Help creating a directory back up shell script WarriorWarren Linux - General 6 04-06-2003 10:56 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration