How to detect url in use in a script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to detect url in use in a script?
# 1  
Old 12-08-2018
How to detect url in use in a script?

Hello,
I have a small script and it runs from web application in below format:
Code:
pipe:///path_to_myscript.sh url1 url2 url3

myscript.sh:
Code:
#!/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?

Thanks in advance
Boris

Last edited by baris35; 12-10-2018 at 05:46 AM.. Reason: latest update
# 2  
Old 12-09-2018
Quote:
Originally Posted by baris35
I have a small script and it runs from web application in below format:
Code:
pipe:///path_to_myscript.sh url1 url2 url3

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?

Thank you.
bakunin
# 3  
Old 12-09-2018
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.

If I type:
Code:
ps aux | grep myscript.sh

it just gives:
Code:
myscript.sh url1 url2 url3

but what I need to see is just:
Code:
myscript.sh url$

Thanks
Boris

Last edited by baris35; 12-09-2018 at 03:29 PM..
# 4  
Old 12-09-2018
If there is gui. insert before each line ((ffmpeg...
Code:
notify-send "Your message, eg start urlX"

in linux command notify-send there is in package libnotify (rhel)
or libnotify-bin (debian)
This User Gave Thanks to nezabudka For This Post:
# 5  
Old 12-09-2018
I have to second bakunin in that your intentions with the script are way less than clear.



Quote:
Originally Posted by baris35
... When url1 is down for some technical issues, script goes to url2, if url2 is also down, goes to url3.

...

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)

Quote:
Special Parameters
.
.
.
! Expands to the process ID of the job most recently placed into the background ...
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?
# 6  
Old 12-09-2018
Dear Rudic,
Thank you for your post.
Regarding below comment, how may I make it terminating current subprocess when related url is off?
Quote:
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

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.

Thank You All
Boris
# 7  
Old 12-09-2018
Quote:
Originally Posted by baris35
... how may I make it terminating current subprocess when related url is off? ...

Wouldn't that command just fail and exit (with respective exit code)?
This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

Script to detect time drift

Hello there, I am not an expert in networking related stuff but I got a requirement to create UNIX script to query our Company's internal time source via NTP for time drift detect and report it when > +/- 50ms. I have been googling a lot but thought to post it in this forum to get a... (17 Replies)
Discussion started by: Green_Star
17 Replies

2. UNIX for Advanced & Expert Users

A script to detect system type

Hi forum, So I am trying to determine the OS type with the following script: #!/usr/bin/sh OStype1=`uname -s` Sunos1=SunOs if then echo "This system is Linux" exit 0 elif then echo "This system is SunOs" exit 0 elif (1 Reply)
Discussion started by: dampio
1 Replies

3. Shell Programming and Scripting

Help with detect with regex and move script

Hi all, I am needing some help with a script that will search for a video file by known extensions and then do a pattern search (I'm guessing via regex) and then based on a match of one type of another move the file to an assigned directory. I would like to do this with either a shell script... (7 Replies)
Discussion started by: Simplify
7 Replies

4. Shell Programming and Scripting

Reading URL using Mechanize and dump all the contents of the URL to a file

Hello, Am very new to perl , please help me here !! I need help in reading a URL from command line using PERL:: Mechanize and needs all the contents from the URL to get into a file. below is the script which i have written so far , #!/usr/bin/perl use LWP::UserAgent; use... (2 Replies)
Discussion started by: scott_cog
2 Replies

5. Shell Programming and Scripting

Detect if script starts from queue

Dear community, what I'm try to do is deny users to run a script without parameters from command bash, but the same script should run without parameters only from crontab. Example runs by crontab:*/5 * * * * /tmp/script.sh Here the normal execution starts every 5 minutes Example #1 runs by... (16 Replies)
Discussion started by: Lord Spectre
16 Replies

6. UNIX for Dummies Questions & Answers

Awk: print all URL addresses between iframe tags without repeating an already printed URL

Here is what I have so far: find . -name "*php*" -or -name "*htm*" | xargs grep -i iframe | awk -F'"' '/<iframe*/{gsub(/.\*iframe>/,"\"");print $2}' Here is an example content of a PHP or HTM(HTML) file: <iframe src="http://ADDRESS_1/?click=5BBB08\" width=1 height=1... (18 Replies)
Discussion started by: striker4o
18 Replies

7. Web Development

Regex to rewrite URL to another URL based on HTTP_HOST?

I am trying to find a way to test some code, but I need to rewrite a specific URL only from a specific HTTP_HOST The call goes out to http://SUB.DOMAIN.COM/showAssignment/7bde10b45efdd7a97629ef2fe01f7303/jsmodule/Nevow.Athena The ID in the middle is always random due to the cookie. I... (5 Replies)
Discussion started by: EXT3FSCK
5 Replies

8. UNIX for Dummies Questions & Answers

how to detect my script is already running

I have a script which must not be run more than once at any given time. THis script will be scheduled to run every 20 mins as a cron job. In my script can i have logic to say if this script is already running from the previous cron, then exit. How do i go about doing that. If you describe the... (11 Replies)
Discussion started by: rmulchandani
11 Replies

9. Shell Programming and Scripting

url calling and parameter passing to url in script

Hi all, I need to write a unix script in which need to call a url. Then need to pass parameters to that url. please help. Regards, gander_ss (1 Reply)
Discussion started by: gander_ss
1 Replies

10. UNIX for Advanced & Expert Users

url calling and parameter passing to url in script

Hi all, I need to write a unix script in which need to call a url. Then need to pass parameters to that url. please help. Regards, gander_ss (1 Reply)
Discussion started by: gander_ss
1 Replies
Login or Register to Ask a Question