Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Config
- onlineUrls="online.txt"
- offlineUrls="offline.txt"
- arrayLimit=200
- parallelInstances=20
- curlTimeout=1
- truncate -s0 "$onlineUrls" "$offlineUrls"
- # Check der URLs
- checkUrls() {
- while read line; do
- if curl -Ls --connect-timeout "$curlTimeout" "$line" &> /dev/null; then
- online+=("$line")
- if [[ ${#online[@]} -eq $arrayLimit ]]; then
- printf "%s\n" "${online[@]}" >> "$onlineUrls"
- online=()
- fi
- else
- offline+=("$line")
- if [[ ${#offline[@]} -eq $arrayLimit ]]; then
- printf "%s\n" "${offline[@]}" >> "$offlineUrls"
- offline=()
- fi
- fi
- done < "$1"
- printf "%s\n" "${online[@]}" >> "$onlineUrls"
- printf "%s\n" "${offline[@]}" >> "$offlineUrls"
- }
- # Parsing
- rm "${1%.*}"[[:digit:]]* 2> /dev/null
- splitLength=$(( $(wc -l "$1" | cut -d ' ' -f1) / $parallelInstances ))
- split -da8 -l"$splitLength" "$1" "${1%.*}"
- online=()
- offline=()
- for file in "${1%.*}"[[:digit:]]*; do
- checkUrls "$file" &
- done
- while jobs -r | grep checkUrls &> /dev/null; do
- sleep 1
- done
- sed -i '/^$/d' online.txt offline.txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement