Hello,
I have a small script and it runs from web application in below format:
pipe:///path_to_myscript.sh url1 url2 url3
myscript.sh:
#!/bin/bash
count=0
while [ "$count" -lt "20" ]
do
count=$((count+1))
exec 3>&1
((ffmpeg -i $1 ...... -f mpegts pipe:1 2>/dev/null 1>&3 ) 2>&1 | \
while read LINE; do echo "$1 $LINE"; done 1>&2 ) 3>&1
PID=$!
wait ($PID)
if [ -n "$2" ]; then
((ffmpeg -i $2 ...... -f mpegts pipe:1 2>/dev/null 1>&3 ) 2>&1 | \
while read LINE; do echo "$2 $LINE"; done 1>&2 ) 3>&1
PID=$!
wait ($PID)
fi
if [ -n "$3" ]; then
((ffmpeg -i $3 ..... -f mpegts pipe:1 2>/dev/null 1>&3 ) 2>&1 | \
while read LINE; do echo "$3 $LINE"; done 1>&2 ) 3>&1
PID=$!
wait ($PID)
fi
sleep 1
done
When I run it, url1, or 2 or 3 runs but I am unable to see which one is in use and I do not wish to run iftop to detect. Htop is not giving any clue.
How may I change this script to be able to see the active url?
I might be a little slow but i can't understand what exactly you want - and, to be honest, the analysis of your script doesn't make it any clearer for me. Could you please explain (for dummies like me) what exactly you want to achieve?
Dear Bakunin,
As the question was not directly related to ffmpeg, I took corresponding portion off the code.
Let's say I have three different tv channel url from three different domain addresses.
The script runs each of them in given order (url 1->2>3). When url1 is down for some technical issues, script goes to url2 . When url2 goes down, it goes to url3 .
When url3 is down, I can make the script respawn so it goes back to url1 once again.
What I'd like to do is to see which one is responding to my script in command line environment.
I have to second bakunin in that your intentions with the script are way less than clear.
I didn't find (maybe overlooked?) the necessary conditional execution in your script. It will run the n (up to three) compound commands, one after the other, regardless of the respective exit codes, and loop until count equals 20. So, 60 commands...
On top, I'm having a hard time to understand your juggling with file descriptors 2 and 3 - what do you want to achieve here?
And, the PID variable used for the (useless) trap won't be set anywhere as ( man bash )
and you're not running anything in background (which would be pointless anyhow as you want to run additional processes only on failure of the predecessors)
Last but not least, is that on purpose that you echo "$1 $LINE" in all three branches?
Dear Rudic,
Thank you for your post.
Regarding below comment, how may I make it terminating current subprocess when related url is off?
Dear Nezabudka,
Thank you for notify tool, I have just installed it and implemented into my script but it shows just the first one.
Original format of url1: http://xx.yy.zz/aa/index.m3u8
I made it: http://x__x.yy.zz/aa/index.m3u8
In that case, it insisted on showing the wrong format as if it was responding but in the background it plays the second one or third one I think.