Last active
December 22, 2015 21:19
-
-
Save eliocapelati/aa6e59a05c68b4fc1ebb to your computer and use it in GitHub Desktop.
Check if the remote proxy is down, and restart your connection.
This file contains hidden or 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 | |
log(){ | |
#See "$ man logger" | |
logger -i -t "CR-CNTLM" "[User:$(whoami)] $1" | |
} | |
##TODO: Impl system count of unsuccessful restarts (Redis?) | |
##MUST BE ROOT | |
go_horse(){ | |
service cntlm restart | |
run_analyze | |
} | |
#Sanity check (supposing you're using POSIX based system :) | |
command -v http >/dev/null 2>&1 || { log >&2 "I require HTTPie(https://github.com/jkbrzt/httpie) but it's not installed. Aborting."; exit 1; } | |
## Perform an analysis of current internet connection, and retry to reconnect | |
run_analyze(){ | |
if http --check-status --ignore-stdin --timeout=5 HEAD http://www.google.com.br &> /dev/null; then | |
log 'Proxy OK!' | |
else | |
case $? in | |
2) log 'Request timed out!' && go_horse;; | |
3) log 'Unexpected HTTP 3xx Redirection!' ;; | |
4) log 'HTTP 4xx Client Error!' && go_horse ;; | |
5) log 'HTTP 5xx Server Error!' && go_horse ;; | |
*) log 'Other Error!' && go_horse;; | |
esac | |
fi | |
} | |
run_analyze |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment