2

excuse my bad english:

This is the situation; I make my own IPTV lists taking the URLs of free sites and passing them to the smart tv, I would like to know which urls work and which ones don't to replace them, and doing it manually is an impossible task, I found the snap bash script to delete old snaps fantastic from the terminal with a single command, something like this would work for me, but OBVIOUSLY I don't know anything about scripts, bash or programming, if you could help me with a bash script that checks all the URLs of a .txt document in the terminal indicating which ones are up and which ones down I would appreciate very much, that would save me a lot of time, I appreciate your help in advance!

3
  • Which distro and version of Linux are you using?
    – user68186
    Sep 22 at 23:49
  • I'm in Ubuntu 20.04! Sep 22 at 23:58
  • Distro doesn't matter here, OP essentially asking someone to create a script for him.
    – Liso
    Sep 23 at 4:05

2 Answers 2

2

Ive tested it a couple of times, seems to work ok.


#!/bin/bash

if [ $# -eq 0 ]
then
    fin=-
else 
    fin=$1
fi

urlarr=( $(cat $fin | strings | tr ',:\/' '\n\n\n' | grep -i "\.com\|\.net\|\.edu\|\.org\|^[0-9].*\.[0-9].*\.[0-9].*\.[0-9].*" | tr '\n' ' ' )  )

for i in ${urlarr[@]}
do
  if ping -c1 -w1 $i 2>&1 >/dev/null
  then
    echo $i is up.
  else
    echo $i is down.
  fi
done

exit $?
9
  • Can you guide me step by step @petep ? I saved the script on gedit with this name "test-url.sh" , becase i have the url list on a .txt document with the name url.txt, i executed on the terminal, but nothing happenned, am i doing somethig good? Sep 23 at 2:56
  • Yes. What kind of urls do you have? Give an example of a few? That may be the problem? Or, I can tell you that the script needs to be run with file input. So you need to type for instance: "cat url.txt | ./test-url.sh" or "./test-url.sh url.txt"
    – petep
    Sep 23 at 3:34
  • Thank you @petep the script works perfectly with this command "./test-url.sh url.txt", you saved me a lot of time, thank you so much! P.S: It was for iptv urls, in some lines or URLS like this: "htps://www.xxxx.com/@xxxx/live" says "Unknown name service" are live channels sometimes up or down like a tiktok live, can the script be fixed for this with any line or something? Sep 23 at 4:20
  • I think I didnt understand the requirments entirely. I thought you wanted to know if the server was up or down. But it looks like you want to know if the tv stream is live, or that is the "streaming" is available?
    – petep
    Sep 23 at 4:32
  • Exactly @petep your script works, but theres more, i want to know if the streaming is available, that's exactly what i want! Sep 23 at 4:35
1

This is the best i can do without your urls to test. If the wget part doesnt work out you can look into replacing w/ curl or ncat (nc) to test wether streams are live.


#!/bin/bash

if [ $# -eq 0 ]
then
    fin=-
else 
    fin=$1
fi

urlarr=( $(cat $fin | strings | grep '://' | grep -i "\.com\|\.net\|\.edu\|\.org\|[0-9].*\.[0-9].*\.[0-9].*\.[0-9].*" | tr '\n' ' ' )  )

for i in ${urlarr[@]}
do
  if wget -q --tries=1 --no-cache --spider -O /dev/null --ignore-length -T 1 "$i"
  then
    echo $i is good.
  else
    echo $i is bad.
  fi
done

exit $?
3
  • So close, i tried the script and works but shows all the streams as if they were live, but they are not, i tried replacing " if wget -q " with ncat and curl but it sends to replace -q with --help i did it but still not showing the real Live status: this is what it shows in the terminal: tiktok.com/@gaming/live is good, says good but they're not live, I appreciate your help @petep Sep 23 at 23:50
  • I downloaded the stream url you gave. Its just an html file it seems. I have no idea how to get the live stream content by linux command line. In other words it could be found in javascript by your browser. It looks like the actual stream content is loaded and viewed by the web browser or app. Tiktok and other platforms probly have an api youre supposed to use to get content from their website. Sorry, that is way beyond me at this time. Its like trying to download one of those video ads embeded in a web page. I dont know how. -Pete
    – petep
    Sep 24 at 1:11
  • 1
    It doesn't matter, the script you gave me helped me a lot, and the new one you made gives me an idea of how a bash script works, you helped me, and I learned, thank you very much! @petep Sep 24 at 1:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.