What i want is script that checks every 30 minutes those files, and when either of them exist, it will start downloading.
i have separete bash script for that like
lataa-720p.sh
and
lataa-1080p.sh
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Checks every 30 minutes if either of the two files exists on the remote server.
If one exists, it runs the corresponding download script (lataa-720p.sh or lataa-1080p.sh).
The server returns a 404 HTML page if the file does not exist.
Here’s a simple bash script to do that:
bash
#!/bin/bash
URL_1080="https://hakunamatata5.org/hls_race_12/1080/1080_.m3u8"
URL_720="https://hakunamatata5.org/hls_race_12/720/720_.m3u8"
while true; do
# Check 1080p file
HTTP_CODE_1080=$(curl -s -o /dev/null -w "%{http_code}" "$URL_1080")
if [ "$HTTP_CODE_1080" -eq 200 ]; then
echo "$(date): 1080p file exists, starting download script."
./lataa-1080p.sh
break
fi
# Check 720p file
HTTP_CODE_720=$(curl -s -o /dev/null -w "%{http_code}" "$URL_720")
if [ "$HTTP_CODE_720" -eq 200 ]; then
echo "$(date): 720p file exists, starting download script."
./lataa-720p.sh
break
fi
echo "$(date): Neither file exists. Checking again in 30 minutes."
sleep 1800 # 1800 seconds = 30 minutes
done
How it works:
It uses curl with -s (silent), -o /dev/null (discard output), and -w "%{http_code}" to get the HTTP status code.
If the status code is 200, the file exists.
It runs the appropriate download script and then exits the loop.
If neither file exists, it waits 30 minutes and checks again.
Usage:
Save this script as check_and_download.sh.
Make it executable: chmod +x check_and_download.sh.
Run it: ./check_and_download.sh.
If you want it to run continuously even after download, remove the break statements.
If you want me to help you with improvements or running it as a background service, just ask!
User
is there better way to check if file exist than curl?
Assistant
Using curl to check if a remote file exists by inspecting the HTTP status code (like 200 for success, 404 for not found) is actually the most straightforward and reliable way for HTTP/HTTPS URLs.
Why curl is usually the best choice:
It directly queries the HTTP server.
You get the exact HTTP status code.
It’s widely available on Linux/Unix systems.
It handles redirects, HTTPS, and other HTTP features.
Alternatives and their pros/cons:
wget
You can use wget with --spider to check if a file exists without downloading it:
bash
wget --spider -q "$URL"
if [ $? -eq 0 ]; then
echo "File exists"
else
echo "File does not exist"
fi
Pros: Also widely available, simple.
Cons: Less control over HTTP status codes, just success/failure.
httping httping is like ping but for HTTP servers. It can check if a URL is reachable but doesn’t tell you if a specific file exists or not.
Using nc or telnet
You could manually send HTTP HEAD requests with nc or telnet, but this is complicated and error-prone.
HEAD request with curl
You can optimize your curl call by using a HEAD request instead of GET, which only fetches headers:
bash
curl -s -o /dev/null -w "%{http_code}" -I "$URL"
This is faster and uses less bandwidth.
Summary:
Best practice: Use curl -I (HEAD request) to check file existence.
wget --spider is a good alternative.
Avoid manual socket programming unless you have very specific needs.