Created
February 5, 2011 12:55
-
-
Save Donearm/812434 to your computer and use it in GitHub Desktop.
Using the proxy_checker.sh script to automatically update the pianobar's config file with a working USA proxy
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 | |
# Using the proxy_checker.sh script to automatically update the | |
# pianobar's config file with a working USA proxy | |
CONFIG="${HOME}/.config/pianobar/config" | |
PROXYCHECK='/mnt/documents/Script/script_proxy_checker.sh' | |
IP=$1 | |
PORT=$2 | |
# call the proxy checker script and catch its exit status | |
$PROXYCHECK $1 $2 | |
if [[ $? = "0" ]]; then | |
# proxy is working, use it | |
# first, assemble the complete config line | |
PROXYLINE="control_proxy = http://${1}:${2}" | |
sed -i 's|^control_proxy.*|'"${PROXYLINE}"'|g' $CONFIG | |
exit 0 | |
else | |
# not working, exit | |
exit 1 | |
fi |
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 | |
# HTTP Proxy Server's IP Address (or URL) | |
proxy_server=$1 | |
# HTTP Proxy Server's Port Number | |
port=$2 | |
# We're trying to reach this url via the given HTTP Proxy Server | |
# (http://www.google.com by default) | |
url="http://www.pandora.com" | |
# Timeout time (in seconds) | |
timeout=20 | |
# We're fetching the return code and assigning it to the $result variable | |
#result=`HEAD -d -p http://$proxy_server:$port -t $timeout $url` | |
#result=`curl -x $proxy_server:$port --head -s --connect-timeout $timeout $url -D - | grep HTTP | awk '{print $2,$3}'` | |
head_request=`wget --server-response --spider -e "http_proxy = $proxy_server:$port" $url -o /tmp/head` | |
result=`grep HTTP /tmp/head | awk '{print $2,$3}'` | |
echo $result | |
# If the return code is 200, we've reached to $url successfully | |
if [ "$result" = '200 OK' ]; then | |
echo "1 (proxy works)" | |
rm -f /tmp/head | |
exit 0 | |
# Otherwise, we've got a problem (either the HTTP Proxy Server does not work | |
# or the request timed out) | |
else | |
echo "0 (proxy does not work or request timed out)" | |
rm -f /tmp/head | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment