Last active
March 21, 2022 18:58
-
-
Save eliranmal/4c04e4fe93aea796e4d48ae1f1a6a5ac to your computer and use it in GitHub Desktop.
takes a list of links as input, and checks each for a successful response
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
main() { | |
log | |
log_ln "hi :)" | |
check_links $(cat -) | |
log_ln "bye bye!" | |
} | |
check_links() { | |
local status=0 | |
log_ln "checking $# links..." | |
for url in "$@"; do | |
check_link "$url" | |
if ((0 == $?)); then | |
log "✔ $url" | |
else | |
status=$? | |
log "✘ $url" | |
fi | |
done | |
log | |
if ((0 == status)); then | |
log_ln "all links are OK 🕺" | |
else | |
log_ln "looks like we have some broken links 🤦♀️" | |
fi | |
} | |
check_link() { | |
local url="$1" | |
curl --output /dev/null --silent --head --fail "$url" | |
} | |
log() { | |
printf ' %s\n' "$1" | |
} | |
log_ln() { | |
log "$1 | |
" | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment