Last active
December 15, 2017 14:06
-
-
Save DanBennettUK/4287a6a28557ba494eaca5fab4eb10f7 to your computer and use it in GitHub Desktop.
Get Moodle Version from URL
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 | |
urlsFile=/tmp/urls.txt | |
resultsFile=/tmp/results.csv | |
urlAppend="theme/upgrade.txt" | |
# Remove results file if already exists | |
if [ -f $resultsFile ] ; then | |
rm $resultsFile | |
fi | |
# Create CSV file and add headers | |
headers=$(echo "site,version") | |
echo "$headers" > "$resultsFile" | |
# Get file from list | |
urls=`cat $urlsFile` | |
for URL in $urls; do | |
# Add trailing slash if needed | |
length=${#URL} | |
last_char=${URL:length-1:1} | |
[[ $last_char != "/" ]] && URL="$URL/"; : | |
# Append path to URL | |
fullURL=$URL$urlAppend | |
FILE="$(mktemp /tmp/getversion.XXXXXX)" | |
wget -q -t 1 -O $FILE $fullURL | |
# Find first instance of version marker | |
result=$(sed -n '/===/p' $FILE | head -1) | |
# Strip unrequired characters | |
resultStripped=$(echo $result | sed 's/===//g') | |
resultStripped=$(echo $resultStripped | tr -d ' ') | |
# Announce find | |
echo "Found version $resultStripped for $URL!" | |
# Append URL to CSV | |
csvOutput=$(echo "$URL,$resultStripped") | |
# Save Result | |
#echo "$csvOutput" > "$resultsFile" | |
echo $csvOutput >> $resultsFile | |
# Delete the temp file | |
rm -f "$FILE" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment