LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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-21-2005, 02:27 PM   #46
infinity42
Member
 
Registered: Apr 2005
Location: England
Distribution: Gentoo
Posts: 142

Rep: Reputation: 16

Oh I know what I have done wrong. Test gets funny if you don't put spaces before and after the ='s.
Try:
Code:
                               if [ "$cmd" = "MAIN" -a "$msg" = "Title Updated" ];then
                                    if [ ! -z "$filename" ];then
                                        echo "$cmd $msg"
                                        echo "Requested Song $filename Has Been Played.  Removing From Playlist."
                                        cat $PL_FILE2|awk '! /'"$filename"'$/ {print $L}'>$PL_FILE2
                                        kill -s USR1 $t
                                        filename=""
                                    fi
                                fi
Hopefully that should fix it.
 
Old 09-21-2005, 02:54 PM   #47
windisch
Member
 
Registered: Nov 2004
Location: Gahanna, Ohio, USA
Distribution: Fedora 9
Posts: 158

Original Poster
Rep: Reputation: 30
The statement is working, but not correctly. It doesn't detect MAIN and Title Updated.

I echoed the script and this is what it outputs:


MAIN /1
Song Requested. Added To Current Playlist
MAIN /1
MAIN /1
MAIN /1
MAIN /1
DECODE: Disc2_05_-1979.mp3
DECODE /1
Song Requested. Added To Current Playlist
MAIN /1
MAIN /1
MAIN /1
MAIN /1

So it is not grabbing the Title Updated part, and I'm not sure why. Thanks again. Take you time and get back with me when you have time. I'm sure this is taking longer than you expected.
 
Old 09-21-2005, 03:48 PM   #48
infinity42
Member
 
Registered: Apr 2005
Location: England
Distribution: Gentoo
Posts: 142

Rep: Reputation: 16
I've noticed another typo, which will stop it picking up msg correctly:
Code:
msg=$(echo $line|sed 's/.*\] \(.*\)/\/1/')
should be
Code:
msg=$(echo $line|sed 's/.*\] \(.*\)/\1/')
 
Old 09-21-2005, 04:49 PM   #49
windisch
Member
 
Registered: Nov 2004
Location: Gahanna, Ohio, USA
Distribution: Fedora 9
Posts: 158

Original Poster
Rep: Reputation: 30
That did it! There's only 1 small thing I can think of. If a song is requested, during the process of decoding, I get the seg fault. How can I get this code below to wait until the Main Title Updated shows in the log?

Code:
 
if [ $curfile = "REQ" ];then
                                if [ ! -f $PL_FILE ];then   #If it doesn't exist then create an empty file using touch and add song to list
                                        echo "Song Requested.  New Request Playlist To Be Created"
                                        mv $PL_FILE2 $PL_FILE
                                        touch $PL_FILE2
                                        chmod 666 $PL_FILE2
                                        echo $line >> $PL_FILE2
                                        kill -s USR2 $t
                                        kill -s USR1 $t
                                else
                                        echo "Song Requested.  Added To Current Playlist"
                                        echo $line >> $PL_FILE2   #Adds To Currently Plaing Request List
                                        kill -s USR1 $t
                                fi

                fi
 
Old 09-21-2005, 05:06 PM   #50
infinity42
Member
 
Registered: Apr 2005
Location: England
Distribution: Gentoo
Posts: 142

Rep: Reputation: 16
Quote:
That did it!
Wooooo!
Quote:
There's only 1 small thing I can think of. If a song is requested, during the process of decoding, I get the seg fault. How can I get this code below to wait until the Main Title Updated shows in the log?
There are a couple of ways to implement it, it depends on one thing: Will there ever be more than one request after a DECODE but before the Main Title Updated?
 
Old 09-21-2005, 05:23 PM   #51
windisch
Member
 
Registered: Nov 2004
Location: Gahanna, Ohio, USA
Distribution: Fedora 9
Posts: 158

Original Poster
Rep: Reputation: 30
I would say, more than likely. It takes between 30-60 seconds for the decoding of a song to finish. At the moment a friend and I listen to it, often at the same time. So there could be multiple requests entered at any time.

Last edited by windisch; 09-22-2005 at 08:05 AM.
 
Old 09-23-2005, 07:40 AM   #52
infinity42
Member
 
Registered: Apr 2005
Location: England
Distribution: Gentoo
Posts: 142

Rep: Reputation: 16
OK.. what we will have to do is to indroduce a request queue. So when a request occurs it checks if there is decoding in progress, and if so queue the request up. Then once the decoding finishes, if there is a request list, add all the requests to the playlist. I implemented this and ended up with something like this:
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.txt'
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"
                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
						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
								kill -s USR2 $t #Should this be below the loop?
							fi
							cat $QUE_FILE|while read line;do
								echo $line >> $PL_FILE2
							done
							kill -s USR1 $t
							rm -f $QUE_FILE
						fi
					fi
				fi
                        fi
                fi
                if [ $curfile = "REQ" ];then
                        echo "REQUEST: $line"
			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
                        	        echo $line >> $PL_FILE2
                        	        kill -s USR2 $t
                        	        kill -s USR1 $t
                        	else
                        	        echo $line >> $PL_FILE2  #Adds To Currently Plaing Request List
                        	        kill -s USR1 $t
                        	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
        fi
done
I don't know if your script is exactly the same as the one I modified here, so I will point out all the changes I have made individually:
Code:
QUE_FILE='request_queue.txt'
Just add a variable to hold the location of the queue file
Code:
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
		kill -s USR2 $t #Should this be below the loop?
	fi
	cat $QUE_FILE|while read line;do
		echo $line >> $PL_FILE2
	done
	kill -s USR1 $t
	rm -f $QUE_FILE
fi
Implement the checking for the queue. A little code duplication here, from the request check below.
Code:
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
	        echo $line >> $PL_FILE2
	        kill -s USR2 $t
	        kill -s USR1 $t
	else
	        echo $line >> $PL_FILE2  #Adds To Currently Plaing Request List
	        kill -s USR1 $t
	fi
fi
If there is decoding in progress then queue the request, otherwise procced as normal.

Hope that makes some kind of sense!
 
Old 09-23-2005, 07:49 AM   #53
windisch
Member
 
Registered: Nov 2004
Location: Gahanna, Ohio, USA
Distribution: Fedora 9
Posts: 158

Original Poster
Rep: Reputation: 30
Looks good, I'll see how it works. The previous version works great, as long as I watch the logs. I can't thank you enough for your help!
 
Old 09-23-2005, 08:38 AM   #54
windisch
Member
 
Registered: Nov 2004
Location: Gahanna, Ohio, USA
Distribution: Fedora 9
Posts: 158

Original Poster
Rep: Reputation: 30
I get an error when I request a song during a decode:

REQUEST: /video3/MythMusic/Live/V/02-Simple Creed.mp3
DECODE: 02-Simple Creed.mp3
REQUEST: /video3/MythMusic/Nobuo Uematsu/Chrono.Cross.OST.(192k).by.rappg04/1-01_Scars_Left_by_Time.mp3
./request: line 54: [: missing `]'

Outside of this, the rest of the script appears to be working.
 
Old 09-23-2005, 08:48 AM   #55
infinity42
Member
 
Registered: Apr 2005
Location: England
Distribution: Gentoo
Posts: 142

Rep: Reputation: 16
Another case of the missing space I think (I'm good at missing spaces):
Code:
if [ ! -z "$filename"];then
should be
Code:
if [ ! -z "$filename" ];then
That should do it
 
Old 09-23-2005, 09:49 AM   #56
windisch
Member
 
Registered: Nov 2004
Location: Gahanna, Ohio, USA
Distribution: Fedora 9
Posts: 158

Original Poster
Rep: Reputation: 30
Once again, great job. The songs waited in the queue, until the song was done decoding. I will have to modify it to wait for the same thing when playing the default list also, but I'll try that first before bothering you again.
 
Old 09-23-2005, 11:03 AM   #57
windisch
Member
 
Registered: Nov 2004
Location: Gahanna, Ohio, USA
Distribution: Fedora 9
Posts: 158

Original Poster
Rep: Reputation: 30
It looks like you added the code in correctly, but it is not detecting if it decoding correctly. I added an echo to see what the contents of $filename is, and its empty.

Code:
 if [ $curfile = "REQ" ];then
    echo "REQUEST: $line"
     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

Also I Modified This
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
         filename=""
          #If there is a request queue, act on the queue
To This:
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
         if [ `wc -c $PL_FILE2|sed 's/ .*//'` -eq 0 ];then
            echo "Empty"
         else
             kill -s USR1 $t
         fi
           filename=""
           #If there is a request queue, act on the queue
So that it would reload the playlist after remove, except for if it was empty, because that causes an error. If its empty, it will let your last section of code take effect.

Last edited by windisch; 09-23-2005 at 11:12 AM.
 
Old 09-23-2005, 11:29 AM   #58
windisch
Member
 
Registered: Nov 2004
Location: Gahanna, Ohio, USA
Distribution: Fedora 9
Posts: 158

Original Poster
Rep: Reputation: 30
I figured out why. Because of the this if statement, its not setting $filename, because it is currently ignoring the log file when the default playlist is playing.

Code:
 if [ ! -z "`echo $line|sed 's/.*==>.*<==.*//'`" ];then
                if [ ! -f $PL_FILE ];then     #Will Ignore Removing Songs If Default List Is Loaded
                        echo "Ignoring Log"
                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
So I modified it to this:
Code:
 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

                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
I hope it works.

Last edited by windisch; 09-23-2005 at 11:33 AM.
 
Old 09-23-2005, 12:56 PM   #59
windisch
Member
 
Registered: Nov 2004
Location: Gahanna, Ohio, USA
Distribution: Fedora 9
Posts: 158

Original Poster
Rep: Reputation: 30
That seems to successfully prevent the error, but I can't seem to figure out how to load the song after it's queued.
 
Old 09-26-2005, 07:46 AM   #60
windisch
Member
 
Registered: Nov 2004
Location: Gahanna, Ohio, USA
Distribution: Fedora 9
Posts: 158

Original Poster
Rep: Reputation: 30
I came across another issue. I noticed that if a filename has parentheses, it will not correctly remove them from the playlist. Is there a way around this with awk? Or do I need to remove the parentheses from the filenames?
 
  


Reply



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 05:32 PM
creating shell script programming using KNOPPIX.. help cinderella Linux - Newbie 4 12-20-2004 07:12 PM
Creating a shell script to run Java program paultaylor Programming 7 11-12-2004 03:11 PM
creating shell script that executes as root regardless of who runs the script? m3kgt Linux - General 13 06-04-2004 10:23 PM
Help creating a directory back up shell script WarriorWarren Linux - General 6 04-06-2003 09:56 AM

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

All times are GMT -5. The time now is 05:36 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
Open Source Consulting | Domain Registration