Newsgroups: comp.unix.questions Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!fitz From: fitz@mml0.meche.rpi.edu (Brian Fitzgerald) Subject: Re: archie (how to automate the search) Message-ID: Summary: sh and expect scripts Nntp-Posting-Host: mml0.meche.rpi.edu Organization: Rensselaer Polytechnic Institute, Troy NY References: <43189@netnews.upenn.edu> Date: 16 May 91 03:28:43 GMT Lines: 86 pravin@eniac.seas.upenn.edu writes: >Is there a way to log on to archie set the mailto, search, etc, do >prog and then mail the results back to me. The only thing >that I will have to do is give as the argument to a command. >Probably someone has already done something like this. If so, I would >appreciate getting it. Please send e-mail or post here. I will >summarize/post anything I get! Around the winter solstice of last year Carl Edman of the University of California, Irvine posted a shell script to comp.unix.shell that does some of what you want (thanks!). I modified it to handle the case of month-day-time type directory entries that occur in the latter six months of the previous year. You can redirect the output of this script to a pipe or a file if you wish. Here it is: #! /bin/sh # Brian P. Fitzgerald # Rensselaer Polytechnic Institute # # original by # Carl Edman # University of California, Irvine # # usage: archie # echo "prog $1" | rsh quiche.cs.mcgill.ca -l archie "" | awk ' BEGIN {months = "JanFebMarAprMayJunJulAugSepOctNovDec"} /Host/ { host = $2 } /Last/ { curm = index(months,$5) ; cury = $6 } /Location:/ { dir = $2 } /FILE/||/DIRECTORY/ { if (index($6,":")) {year = cury if (index(months,$4) > curm) year = cury - 1} else year = $6 printf "%3s %2s %4s %7s /%s:/%s/%s\n",$4,$5,year,$3,host,dir,$7 } { next }' - | sort +2nr -3 +0Mr -1 +1nr -2 Lately, I have been using the following "expect" script (Thanks for creating expect, Don Libes! Please try not to break "expect" when you fix TTY security, Dan Bernstein and friends!) ----- #!/usr/local/bin/expect # archie # Log in to the archie index server at McGill University # Brian P. Fitzgerald # Department of Mechanical Engineering # Rensselaer Polytechnic Institute # expect is available by anonymous ftp from durer.cme.nist.gov as # /pub/expect.shar.Z and from many other places, such as uunet. # tcl is available by anonymous ftp from ucbvax.berkeley.edu # as /pub/tcl.tar.Z, and from many other places. set CINTR \CC set CSUSP \CZ send_user "type ^C to exit, ^Z to suspend\n" spawn telnet quiche.cs.mcgill.ca expect *login:* {send archie\r} \ *unknown*\r* {exit 1} \ *unreachable* {exit 1} expect *archie>* {send set pager\r} expect *archie>* {send set maxhits 20\r} expect *archie>* {send set term vt100\r} expect *archie>* {send set sortby time\r} expect *archie>* {send set mailto you@your.edu\r} interact $CINTR {exit 0} \ $CSUSP {exec kill -STOP 0} ----- These programs have worked satisfactorily for me for a while now, but comments and suggestions are always welcome. Brian -- We need to secure as many banks in our computer banks as possible. We don't want no one else's help, but yours. Miller's Comsumer Service