Mail Archives: cygwin/2005/11/06/19:01:44
Brian Dessent wrote:
> Maybe a starting point would be a awk[1] script that lives in the
> base-files package that grabs mirrors.lst and downloads some relatively
> small package from every mirror, and generates a report. That way, we
> could at least say "try running mirror-check.awk" when users have
> problems with mirrors, rather than just "play around until you find a
> mirror you like."
Here is a first stab at such a script. It gets mirrors.lst and then downloads
setup.bz2 from each http mirror and reports the elapsed time. It doesn't sort
the results or anything, but I just wanted to see if it was possible to do this
in gawk.
#!/usr/bin/awk -f
BEGIN {
CygwinSite = "/inet/tcp/0/cygwin.com/80"
MirrorsUrl = "http://cygwin.com/mirrors.lst"
RS = ORS = "\r\n\r\n"
print "GET " MirrorsUrl " HTTP/1.0" |& CygwinSite
CygwinSite |& getline Header
if (Header !~ /^HTTP\/1\.[10] 2[0-9][0-9]/) {
printf "Error fetching %s. Response was:\n%s\n", MirrorsUrl, Header
exit
}
RS = ORS = "\n"
while ((CygwinSite |& getline Mirror) > 0) {
split(Mirror, Fields, ";")
if (Fields[1] ~ /^http:\/\//) {
AwkFetch = "/bin/time /bin/awk 'BEGIN { site = \"/inet/tcp/0/" \
Fields[2] "/80\"; RS = ORS = \"\\r\\n\\r\\n\"; print \"GET " \
Fields[1] "/setup.bz2 HTTP/1.0\" |& site; while " \
"((site |& getline) > 0); close (site); }' 2>&1"
while((AwkFetch | getline Output) > 0) {
if (match(Output, /([0-9]+:[0-9]+\.[0-9]+)elapsed/, Elap)) {
printf "Mirror %s (located in %s, %s) time %s\n", \
Fields[2], Fields[4], Fields[3], Elap[1]
break
}
}
close(AwkFetch)
}
}
close(CygwinSite)
}
Obviously this is pretty rough (no ftp: support, assumes port :80 instead of
parsing it from the URL, etc.) And it would be a lot prettier in perl or
something but the whole reason for this exercise was to see if it was possible
to write a script in pure awk that could do this.
Brian
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
- Raw text -