Friday, November 23, 2007

Script to Download

Today, my colleague came to me when I was about to knock off (5 minutes before 6 !). He was telling me that his account in the Sun Downloads cannot allow him to download the Application Server. I have no idea why his account cannot work, but mine worked perfectly. The "Application Server 7 Update 9 SE - Solaris Sparc Bundle, English" is about 126.52MB and it is going to take a while to download. Our office's internet connection is really slow, and it will take you at least an hour to download, if you are lucky.

Of course I wanted to help my colleague, on the other hand I do not want to stay back either. Also, I do not want to leave my notebook unattended in the office. If I would capture the HTTP headers at the final click, I should be able replay that as a script. With this approach, the script does not have to worry about session. I launched LiveHTTPheaders to assist me to capture the HTTP headers. Below is the screen capture:

To prove that my concept works, I captured all these HTTP headers and put them in a script to program Wget to download it for me in a Solaris server. Instead of running the script with nohup and puting it as a background job, I ran that as a batch process using "at now". If you were to run with 'nohup command ... &', you wouldn't be able to logout cleanly from your connection. Here is how I scripted the whole thing

#! /bin/sh

h2='User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20071025 Firefox/'
h3='Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5'
h4='Accept-Language: en-us,en;q=0.5'
h5='Accept-Encoding: gzip,deflate'
h6='Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7'
h7='Cookie: s_cc=true; s_sq=; SessionCredentials=6664883992855580291'

wget \
--header="$h1" \
--header="$h2" \
--header="$h3" \
--header="$h4" \
--header="$h5" \
--header="$h6" \
--header="$h7" \
-O sun-appserver7-solaris-sparc-ur9.tar.gz \

Shell script saved the day.

Labels: ,


Blogger Raymond Tay said...

This technique is really cool :-)

12:00 PM  

Post a Comment

<< Home