Advertisement
AlecsD

check.sh

Oct 19th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.07 KB | None | 0 0
  1. #!/bin/bash
  2. # Config
  3. onlineUrls="online.txt"
  4. offlineUrls="offline.txt"
  5. arrayLimit=200
  6. parallelInstances=20
  7. curlTimeout=1
  8.  
  9. truncate -s0 "$onlineUrls" "$offlineUrls"
  10.  
  11. # Check der URLs
  12. checkUrls() {
  13.     while read line; do
  14.         if curl -Ls --connect-timeout "$curlTimeout" "$line" &> /dev/null; then
  15.             online+=("$line")
  16.             if [[ ${#online[@]} -eq $arrayLimit ]]; then
  17.                 printf "%s\n" "${online[@]}" >> "$onlineUrls"
  18.                 online=()
  19.             fi
  20.         else
  21.             offline+=("$line")
  22.             if [[ ${#offline[@]} -eq $arrayLimit ]]; then
  23.                 printf "%s\n" "${offline[@]}" >> "$offlineUrls"
  24.                 offline=()
  25.             fi
  26.         fi
  27.     done < "$1"
  28.  
  29.     printf "%s\n" "${online[@]}" >> "$onlineUrls"
  30.     printf "%s\n" "${offline[@]}" >> "$offlineUrls"
  31. }
  32.  
  33. # Parsing
  34. rm "${1%.*}"[[:digit:]]* 2> /dev/null
  35. splitLength=$(( $(wc -l "$1" | cut -d ' ' -f1) / $parallelInstances ))
  36. split -da8 -l"$splitLength" "$1" "${1%.*}"
  37.  
  38. online=()
  39. offline=()
  40.  
  41. for file in "${1%.*}"[[:digit:]]*; do
  42.     checkUrls "$file" &
  43. done
  44.  
  45. while jobs -r | grep checkUrls &> /dev/null; do
  46.     sleep 1
  47. done
  48.  
  49. sed -i '/^$/d' online.txt offline.txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement