Created
April 26, 2024 12:54
-
-
Save marcbria/0156044d504f49ffffcb6a03ddb4c9e5 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
DOMAIN="demo.publicknowledgeproject.org/ojs3/testdrive/index.php" # Replace with your domain | |
JOURNAL="testdrive-journal" # Replace with your journal's slug | |
# Initialize variables | |
errors=0 | |
valid=0 | |
redirected=0 | |
unknown=0 | |
count=1 | |
# Check if the url is valid or not. | |
check_url() { | |
url=$1 | |
response_code=$(curl -ks -o /dev/null -w "%{http_code}" "$url") | |
case $response_code in | |
# Not Found are errors | |
404) | |
echo "$count --> INVALID - Not Found" | |
echo " $response_code: $url" | |
((errors++)) | |
;; | |
# Active are valid | |
200) | |
echo "$count --> VALID - Active" | |
echo " $response_code: $url" | |
((valid++)) | |
;; | |
# Unauthorized are valid | |
403) | |
echo "$count --> VALID - Unauthorized " | |
echo " $response_code: $url" | |
((valid++)) | |
;; | |
# Permanent redirections are valid | |
301 | 308) | |
echo "$count --> VALID - Permanent redirection" | |
echo " $response_code: $url" | |
((redirected++)) | |
((valid++)) | |
;; | |
# Temporal redirections are valid | |
302 | 303 | 307) | |
echo "$count --> VALID - Temporal redirection" | |
echo " $response_code: $url" | |
((redirected++)) | |
((valid++)) | |
;; | |
# Anything else is Unknown and are invalid. | |
*) | |
echo "$count --> UNKNOWN - Need to be checked" | |
echo " $response_code: $url" | |
((unknown++)) | |
((errors++)) | |
;; | |
esac | |
((count++)) | |
} | |
# Some sample list of URLs need to be adapted to each context. | |
# Use one of those (setting urlsList variable) or create your own. | |
# No Restful and multi-tenant installation | |
listNoRestMulti=( | |
"https://$DOMAIN" # Main page | |
"https://$DOMAIN/index" # OJS site's index | |
"https://$DOMAIN/$JOURNAL/about" # Journal's verbs | |
"https://$DOMAIN/$JOURNAL/\$\$\$call\$\$\$/page/page/css?name=stylesheet" # $$$call$$$ | |
"https://$DOMAIN/$JOURNAL/api/v1/contexts/1" # API in journal | |
"https://$DOMAIN/$JOURNAL/oai" # OAI in journal | |
"https://$DOMAIN/index/install/install" # Installation | |
) | |
# Restful and single-tenant installation (untested list) | |
listRestSingle=( | |
"https://$DOMAIN" # Main page | |
"https://$DOMAIN/index" # OJS site's index | |
"https://$DOMAIN/$JOURNAL/about" # Journal's verbs | |
"https://$DOMAIN/$JOURNAL/\$\$\$call\$\$\$/page/page/css?name=stylesheet" # $$$call$$$ | |
"https://$DOMAIN/$JOURNAL/api/v1/contexts/1" # API in journal | |
"https://$DOMAIN/$JOURNAL/oai" # OAI in journal | |
"https://$DOMAIN/index/install/install" # Installation | |
"https://$DOMAIN/admin" # Admin page | |
"https://$DOMAIN/api/v1/contexts/1" # API in site | |
"https://$DOMAIN/oai" # OAI in site | |
) | |
urlList='' | |
# Select URLs list based on parameter | |
if [[ "$1" == "listNoRestMulti" ]]; then | |
urlList=("${listNoRestMulti[@]}") | |
elif [[ "$1" == "listRestSingle" ]]; then | |
urlList=("${listRestSingle[@]}") | |
else | |
echo "Invalid parameter." | |
echo "Please provide a valid urlList like 'listNoRestMulti', 'listRestSingle'..." | |
exit 1 | |
fi | |
# Iterate the selected list | |
for url in "${urlList[@]}"; do | |
check_url "$url" | |
done | |
# Summarize and show results | |
echo "" | |
echo "SUMMARY OF YOUR URL's HEALTH:" | |
echo "- Active: $valid - Those urls are valid." | |
echo " - Redirect: $redirected - Redirected url are usually valid, but url destination need to be add to the list and checked too." | |
echo "- Errors found: $errors - Errors NEED that be fixed, like notFound and other unkown codes." | |
echo " - Unkown: $unknown - URLs that returned an unexpected code and need a detailed review. Considered errors." | |
echo "" | |
if [ $errors -eq 0 ]; then | |
echo "RESULT: Looks like your site looks healthy" | |
else | |
echo "RESULT: Your site fails. There are $errors errors that probably need to be fixed." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment