Wednesday, August 29, 2007

Better Internet Bandwidth Utilisation

My office Internet connection is not fast and it will not be efficient to download something biggish during the normal office hour. Also, I don't want to leave my notebook unattended outside office hour.

I wrote a simple proof-of-concept web frontend to assist me to download file at scheduled time slot. A Tcl CGI script is written to dynamically talk to at (execute command at a later time) to achieve this.

Imagine you want to download the Rocks Cluster DVD ISO , which is 4,045,514,752 Bytes in size. All you have to do is to provide the web frontend with the URL and time (how many hour/min later) to download this file. Email notification (currently not implemented) can be easily incorporated at the end of the download if needed. Below shows the web page:

Skeleton of the CGI program is given below:

#! /usr/sfw/bin/tclsh

package require cgi

set when [cgi_import when]
set unit [cgi_import unit]
set url  [cgi_import url]

set dir /var/apache/htdocs/your-dl

set fp [open "|at -m now + $when $unit" w]
fconfigure $fp -buffering line
set filename [file tail $url]
puts $fp "cd $dir"
puts $fp "/usr/local/bin/curl --location --silent --remote-name $url"

set now [clock format [clock seconds]]
set then [clock format [clock scan "now + $when $unit"]]
puts "Content-type: text/plain\n"
puts "Now is $now"
puts "Scheduled to download at $then"
puts ""
puts "Check download area here"

Curl and Cgi.tcl (a Tcl package for CGI) are used in this setup. The whole setup runs on Solaris 10 with the built-in Apache 2. I believe this demo web site can offload some of the daytime Internet traffic.

Labels: , , , ,


Post a Comment

<< Home