Set proxy if @work

I got tired of manually setting http_proxy & ftp_proxy on my job computer that I sometimes use at work (proxy needed) or at home (no proxy needed) so I came up with this dirty, but workable pice of bash script.

The ip x.x.x.x in the script below is the office IP (assigned by DHCP, but always resolved to static IP address based on my MAC)

#Set proxy if in office
ip=$(/sbin/ifconfig eth0 | grep -e".*inet addr.*" | sed -e "s/.*inet addr://g" | sed -e"s/ .*//g")
if [ $ip = "x.x.x.x" ]
then
  http_proxy="http://office.proxy.com:80"
  ftp_proxy="http://office.proxy.com:80"
  export http_proxy
  export ftp_proxy
fi

The above is part of a bigger script (myVariables.sh) that set other stuff as well, and this script is called from my bash profile (~/.bashrc) so every time I create a bash shell I get this set.

This entry was posted in bash, shell. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s