LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-15-2012, 03:35 AM   #1
devmoc
Member
 
Registered: Sep 2005
Posts: 38

Rep: Reputation: 15
Restart rtmpdump in a script


Hello all. I want to run a rtmpdump script in a cronjob. The problem is that sometimes rtmpdump quits unexpectedly due to server problems or dropped packets, and I cannot figure out how to make it restart within a script and change the output filename.

Basically I want to do this pseudo code:

#!/bin/bash
rtmpdump -r "xxxxx" -o output#.xxx
every xx minutes, check if rtmpdump is still running?
yes, keep going
no, rerun the rtmpdump command but append a number to the output filename so I don't overwrite any file.

Thanks for any assistance.
 
Old 06-16-2012, 02:04 PM   #2
rosehosting.com
Member
 
Registered: Jun 2012
Location: Missouri, USA
Posts: 233

Rep: Reputation: 64
The following script should work:
Code:
#!/bin/bash
START_COMMAND="rtmpdump -r "xxxxx" -o output#.xxx"
pgrep rtmpdump
if [ $? -ne 0 ] # if rtmpdump not running
then
 $START_COMMAND
fi



Quote:
Originally Posted by devmoc View Post
Hello all. I want to run a rtmpdump script in a cronjob. The problem is that sometimes rtmpdump quits unexpectedly due to server problems or dropped packets, and I cannot figure out how to make it restart within a script and change the output filename.

Basically I want to do this pseudo code:

#!/bin/bash
rtmpdump -r "xxxxx" -o output#.xxx
every xx minutes, check if rtmpdump is still running?
yes, keep going
no, rerun the rtmpdump command but append a number to the output filename so I don't overwrite any file.

Thanks for any assistance.
 
Old 06-20-2012, 03:06 AM   #3
devmoc
Member
 
Registered: Sep 2005
Posts: 38

Original Poster
Rep: Reputation: 15
Thanks. I'll try this. I also want to increment the output file name, so I will attempt something like this and see if it works.

Code:
#!/bin/bash
a=1
START_COMMAND="rtmpdump -r "xxxxx" -o output"$a".xxx"
pgrep rtmpdump
if [ $? -ne 0 ] # if rtmpdump not running
then
 let "a+=1"
 $START_COMMAND
fi
 
Old 06-20-2012, 09:33 AM   #4
devmoc
Member
 
Registered: Sep 2005
Posts: 38

Original Poster
Rep: Reputation: 15
I tried the suggested script and it does not restart rtmpdump if it dies.
 
Old 06-21-2012, 10:04 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.10, Centos 7.5
Posts: 17,705

Rep: Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494
That's because there's no loop... you need to add something like
Code:
a=1
START_COMMAND="rtmpdump -r "xxxxx" -o output"$a".xxx"
while 1
do 
    if [[ $? -ne 0 ]] # if rtmpdump not running
    then
        let "a+=1"
        $START_COMMAND
    else
        break
    fi
done
NB: untested, but you get the idea.
Also http://tldp.org/LDP/abs/html/testcon...ml#DBLBRACKETS
 
Old 06-22-2012, 01:55 AM   #6
devmoc
Member
 
Registered: Sep 2005
Posts: 38

Original Poster
Rep: Reputation: 15
I couldn't get that version to work, but I did manage to get the version below working. If rtmpdump dies then it restarts and increments the number on the filename. When you kill this script you also have to kill the currently running rtmpdump process separately.

Code:
#!/bin/bash
a=1
while (true); do
rtmpdump <options> -o output"$a".flv
let "a+=1"
done
 
  


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
[SOLVED] script to restart Tomcat . . . dgg Programming 6 12-19-2011 04:40 PM
Bash script to restart a dead script nathanpayne Programming 9 07-22-2011 11:28 PM
[SOLVED] how to restart the pc for in a script? joesto Linux - Newbie 5 10-31-2010 02:23 AM
restart script glennbtn Linux - Newbie 1 07-20-2010 06:13 AM
Restart script blablaman Linux - Newbie 1 08-20-2004 07:09 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:20 AM.

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