I am trying to set a proxy on a rotating basis; but my export
commands are not working. I'm using CentOS 7.
I've gone back to basics and tested a really simple bash script, which sets and unsets environment variables, and then tests them. The environment variables appear set properly, but my external IP is still showing as my local IP.
$1
is an address in the form http://119.27.177.169:80
#!/bin/bash
function set() {
export http_proxy="$1/" # not working
export https_proxy="$1/" # not working
testExtIP
}
function unset() {
unset http_proxy
unset https_proxy
testExtIP
}
function testExtIP() {
externalHTTP=$(curl -s http://api.ipify.org) # an API that echos the external IP quickly
externalHTTPS=$(curl -s https://api.ipify.org)
echo "External HTTP: $externalHTTP; external HTTPS: $externalHTTPS"
}
case "$1" in
'set')
set $2 # speed
;;
'unset')
unset $2
;;
'test')
testExtIP $2
;;
*)
echo "Usage: $0 $versum [set|unset|test]"
;;
esac
I would like the script to return:
External HTTP: 119.27.177.169; external HTTPS: 119.27.177.169
But my external IP isn't set:
External HTTP: **SERVERIP**; external HTTPS: **SERVERIP**
which I've tested using various tools. Why is the export command not working? Am I missing something important?
set
andunset
are shell built in commands. Just should pick other names for your functions. – Kusalananda Jan 20 '18 at 12:33