No wget, No Problem!

I don’t post enough, so I am going to try to make some day to day blog posts here and there.

So today, I had an interesting experience with some hardware at work running a custom Linux OS. It was pretty locked down, and there is no simple “yum/apt-get install.” To make matters worse, most “core” packages were custom and didn’t exist. Some of these missing packages were wget, rsync, or curl.

I was tasked with putting a rather large file on this system, and was told the best way was to take a USB stick and plug it in. See…I am lazy (it was also -25 degrees outside to get to Building B). This means I needed to waste my time walking in the tundra I call Chiberia, when I could have been hammering away at something else.

First thing I do, login the box. Alright…so I have remote access. Let’s see, I can resolve internal addresses. Typical. Hmm…what about other addresses? Hmm interesting, I can reach them as well. Telnet to 80? Cool, that works too! wget failed…as expected…meh, worth a shot. Hmm, this is custom Linux, I mean…they really shouldn’t touch python. I wonder…BINGO! I got a python shell! In the shell, I ran the below script to essentially “wget” a file onto the box. Took a while, but it worked.

import urllib
urllib.urlretrieve("http://www.example.com/bigoldfile.tgz", "bigoldfile.tgz")

Sure this works, but again…i’m lazy; this is a bit of typing anyways. I want something scriptable that I can just call with a url. Behold, my wget.py. I know, nothing fancy, but it works. Just call, python wget.py <some_url>. Enjoy it for what it’s worth.

#!/usr/bin/python
import urllib
import sys

url = str(sys.argv[1])
file_name = url.split("/")[-1]
urllib.urlretrieve (url, file_name)

Leave a Reply

Your email address will not be published. Required fields are marked *