LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-26-2006, 08:43 AM   #1
GavB
Member
 
Registered: Nov 2006
Posts: 54

Rep: Reputation: 15
Help with a script please


Hi, I'm new to this but am getting there slowly but surely. Sorry if this is long winded.

I just have a slight problem an thought someone might be able to help me.

Basically, I have mpg123 tuned in to a Shoutcast stream and it is relayed to another server (at lower bitrate) using a perl script (a very slightly modified version of this www .netwise.it/xml/perlmonks/?node_id=66521) - I have 2 streams running, 48k and 24k.

The only trouble is that it is quite unstable and sometimes stops, so I have knocked together a script that checks that the streams are still running (10 seconds between each), here it is:
Code:
#!/bin/bash

while [ 1 ] 

do 

if [ ! "$(ps ax | grep script1.pl | grep -v grep)" ]
then
  /path/to/script1.pl &
fi

sleep 10

if [ ! "$(ps ax | grep script2.pl | grep -v grep)" ]
then
  /path/to/script2.pl &
fi

sleep 10

done
The only problem is that sometimes the stream seems to freeze and the pl script doesnt actually die.

I have found that when it all works well, and I run ps ax | grep script1.pl | grep -v grep I get this as the output
Code:
9582 ?        S      0:00 /usr/bin/perl /path/to/script1.pl
but when it has frozen, I get this (as an example)
Code:
9582 ?        R      1.24 /usr/bin/perl /path/to/script1.pl
I'll be honest - I'm not entirely sure what the 'S' and 'R' above mean, but it seems that if the script is running well it displays 'S' and if not it displays 'R' form what I've seen. Is there a way to use the grep command to only display 'R' or 'S'? If so it will be easy becase I can just write the script to stop and restart the streams if the output is 'R'. Or is there an alternative that I could use.

Maybe I've got it scompletely twisted and theres just a much better way.

You'll have to excuse my complete lack of understanding with this and I have probably explained it badly lol, like I say I've only just started learning.

Thanks for your help
 
Old 11-26-2006, 09:03 AM   #2
fordeck
Member
 
Registered: Oct 2006
Location: Utah
Posts: 520

Rep: Reputation: 61
You can test for the "R" or "S" like this:

Code:
 echo "9582 ?        S      0:00 /usr/bin/perl /path/to/script1.pl" | awk '{print $3}'
Although I'm sure there is a better way to fix this.
 
Old 11-26-2006, 09:20 AM   #3
GavB
Member
 
Registered: Nov 2006
Posts: 54

Original Poster
Rep: Reputation: 15
Ahhh, I see, I was looking at what 'awk' does - I see what it is now.

Thanks for your quick reply.

This is what I have now, so I'll see how it goes. I get the feeling that it's pretty messy so I'll have to work on it and find a better way.

Code:
#!/bin/bash

while [ 1 ] 

do 

if [ ! "$(ps ax | grep script1.pl | grep -v grep)" ]
then
  /path/to/script1.pl &
fi

if [ "$(ps ax | grep script1.pl | grep -v grep | awk '{print $3}')" == "R" ]
then

  killall script1.pl

  /path/to/script1.pl &

fi

sleep 10

if [ ! "$(ps ax | grep script2.pl | grep -v grep)" ]
then
  /path/to/script2.pl &
fi

if [ "$(ps ax | grep script2.pl | grep -v grep | awk '{print $3}')" == "R" ]
then

  killall script2.pl

  /path/to/script2.pl &

fi

sleep 10

done
PS: after some experimenting, I found that the problem with itnfreezing is due to mpg123 stopping for some reason.

Last edited by GavB; 11-26-2006 at 09:30 AM.
 
  


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
Iptables (with masq) troubleshooting, very simple script attached script and logs. xinu Linux - Networking 13 11-01-2007 04:19 AM
Directory listing - Calling shell script from a CGI script seran Programming 6 08-11-2005 11:08 PM
creating shell script that executes as root regardless of who runs the script? m3kgt Linux - General 13 06-04-2004 10:23 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
linux 9 and java script error - premature end of script header sibil Linux - Newbie 0 01-06-2004 04:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:03 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