Created
February 21, 2018 18:07
-
-
Save xse/5c752ce937b6058db1930912d72ee371 to your computer and use it in GitHub Desktop.
check chocolatey main package feed ( web & cli ) every 5 minutes
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
# | |
# check_choco.sh : check website and cli every 5 minutes for "0 packages found" and log errors | |
# | |
# requierements : - bash shell used by git on windows | |
# - a "logs" folder in the same directory with this script | |
# | |
# outputs : - cli outputs only if errors | |
# - errors logfile : check_choco.log | |
# - website page dump and/or cli --trace dump in "logs" folder only if errors | |
# | |
# usage : bash check_choco.sh pkg1 pkg2 pkg3 ... | |
# | |
check_website () { | |
webreply=`curl.exe -s https://chocolatey.org/packages?q=$1 -o webreply.tmp` | |
webpkgnumber=`cat webreply.tmp | grep -o "Search for \"$1\" returned [0-9]* packages" | sed 's/[^0-9]//g'` | |
if [ "$webpkgnumber" -eq "0" ]; then | |
echo "[UTC:$(date --utc +%F_%T)][website] $webpkgnumber packages found for \"$1\" ! ($(cat webreply.tmp | grep -o "You are on web.[0-9]*.")) see html page logs/$(date --utc +%F_%T)_$1_error.html" | |
echo "[UTC:$(date --utc +%F_%T)][website] $webpkgnumber packages found for \"$1\" ! ($(cat webreply.tmp | grep -o "You are on web.[0-9]*.")) see html page logs/$(date --utc +%F_%T)_$1_error.html" >> check_choco.log | |
mv webreply.tmp logs/$(date --utc +%F_%T)_$1_error.html | |
else | |
#echo "[UTC:$(date --utc +%F_%T)][website] $webpkgnumber packages found for \"$1\" ! ($(cat webreply.tmp | grep -o "You are on web.[0-9]*."))" | |
rm webreply.tmp | |
fi | |
} | |
check_cli () { | |
clireply=`choco search $1 --trace > clireply.tmp` | |
clipkgnumber=`cat clireply.tmp | grep -o "[0-9]* packages found." | sed 's/[^0-9]//g'` | |
if [ "$clipkgnumber" -eq "0" ]; then | |
echo "[UTC:$(date --utc +%F_%T)][cli] $clipkgnumber packages found for \"$1\" ! see trace output logs/$(date --utc +%F_%T)_$1_error.txt" | |
echo "[UTC:$(date --utc +%F_%T)][cli] $clipkgnumber packages found for \"$1\" ! see trace output logs/$(date --utc +%F_%T)_$1_error.txt" >> check_choco.log | |
mv clireply.tmp logs/$(date --utc +%F_%T)_$1_error.txt | |
else | |
#echo "[UTC:$(date --utc +%F_%T)][cli] $clipkgnumber packages found for \"$1\" !" | |
rm clireply.tmp | |
fi | |
} | |
while true; do | |
for i in $*; do | |
check_website $i | |
check_cli $i | |
done | |
sleep 300 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment