Newsgroup: icdoc.general


Article 279 of icdoc.general:
Newsgroups: icdoc.general
Path: icdoc!dds
From: dds@doc.ic.ac.uk (Diomidis Spinellis)
Subject: Get a copy of you library record
Nntp-Posting-Host: dirty.doc.ic.ac.uk
Message-ID: <1991Dec9.142445.17482@doc.ic.ac.uk>
Organization: Dept. of Computing, Imperial College, London, UK
Date: Mon, 9 Dec 1991 14:24:45 GMT
Distribution: icdoc
Lines: 134
Content-Length: 3996
The following script will connect to the college library computer,
retrieve your library record and print it on its standard output.  You
need to tailor it by adding you barcode number and your PIN number.
Your machine must know about the spadg or tpad service and the x29-serv
host.  On some machines you may need to change the location of the Perl
executable in the first line of the script (use the command which perl
to find it out).  Install it in your bin directory and set its mode to
user read and execute (chmod 500 libinfo), as it will contain your PIN
number.  (Some may consider this a security risk, those should not
install it).

Enjoy

Diomidis

#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	libinfo
# This archive created: Mon Dec  9 14:21:01 1991
export PATH; PATH=/bin:$PATH
echo shar: extracting "'libinfo'" '(2202 characters)'
if test -f 'libinfo'
then
	echo shar: will not over-write existing file "'libinfo'"
else
sed 's/^X//' << \SHAR_EOF > 'libinfo'
X#!/usr/local/bin/perl
X#
X# Connect to the library and get a copy of your record.
X#
X# Diomidis Spinellis 1991
X#
X# $Header$
X#
X
X$barcode = 'XXXXXXXXXX';	# REPLACE THE Xs with YOUR BARCODE HERE
X$pin = 'XXXX';			# REPLACE THE Xs with YOUR PIN
X
X($program = $0) =~ s%.*/%%;
X
X
X$AF_INET = $PF_INET = 2; 	# Should check the .h file
X$SOCK_STREAM = 1; 		# Should check the .h file
X
X$sockaddr = 'S n a4 x8';
X
Xchop ($hostname = `hostname`);
X
X($USER = getlogin) || ($USER = $ENV{'USER'}) || (($USER) = getpwuid($<));;
X
X(($name, $aliases, $port, $proto) = getservbyname('spadg', 'tcp')) ||
X(($name, $aliases, $port, $proto) = getservbyname('tpad', 'tcp')) ||
Xdie "no tcp service for \"tpad\"";
X#printf "port is %d\n", $port;
X
X(($name, $aliases, $type, $len, $thisaddr) = gethostbyname($hostname))
X    || die "no localhost \"$hostname\"\n";
X(($name, $aliases, $type, $len, $thataddr) = gethostbyname('x29-serv'))
X    || die "no server host \"x29-serv\"\n";
X#printf "server is %s\n", $name;
X
X($name, $aliases, $proto) = getprotobyname('tcp'); 
X
X#print "protocol name = [$name] ($proto)\n";
X
X$this = pack($sockaddr, $AF_INET, 0, $thisaddr);
X$that = pack($sockaddr, $AF_INET, $port, $thataddr);
X
X#print "socket(SERVER, $PF_INET, $SOCK_STREAM, $proto )";
Xsocket(SERVER, $PF_INET, $SOCK_STREAM, $proto ) || die "socket: $!";
X
Xbind(SERVER, $this) || die "bind: $!";
X
Xconnect(SERVER, $that) || die "connect: $!";
X
Xselect(SERVER); $| = 1; select(STDOUT);
X
Xprint SERVER "ic.lib\n";
X
Xwhile (<SERVER>) {
X    last if /^NETWORK/;
X} 
Xsleep(1);
Xprint SERVER "LIBRARY\n";
Xwhile (<SERVER>) {
X    last if /Other/;
X} 
Xprint SERVER "7\n";		# Other terminal
Xprint SERVER "2\n";		# Your own use
Xprint SERVER "3\n";		# User record
Xprint SERVER "$barcode\n";	# Barcode
Xprint SERVER "$pin\n";		# PIN
Xprint SERVER "LOAN\n+\n+\n+\n+\n";		# Loan
Xprint SERVER "RESER\n+\n+\n+\n+\n/\n/\n/\nEXIT\n";	# Finish
X
Xwhile (<SERVER>) {
X	if (/^\rLOANS/ .. /^\rEnter[^+]+$/) { &process($_); }
X	if (/^\rRESERVATIONS/ .. /^\rEnter[^+]+$/) { &process($_); }
X}
X
Xclose SERVER;
X
Xexit !$ok;
X
Xsub process
X{
X	if (
X		!/^\r$/ && 
X		!/^\rEnter/ && 
X		!/Command \+ is not/ &&
X		!/^\r\*\*\* Continued/ &&
X		!/\(help\)\:/ &&
X		!$seen{$_}
X	) { 
X		$seen{$_} = 1;
X		print;
X	}
X}
SHAR_EOF
if test 2202 -ne "`wc -c < 'libinfo'`"
then
	echo shar: error transmitting "'libinfo'" '(should have been 2202 characters)'
fi
chmod +x 'libinfo'
fi # end of overwriting check
#	End of shell archive
exit 0
-- 
Diomidis Spinellis                  Internet:                 dds@doc.ic.ac.uk
Department of Computing             UUCP:                    ...!ukc!icdoc!dds
Imperial College, London SW7        #include "/dev/tty"




Newsgroup icdoc.general contents
Newsgroup list
Diomidis Spinellis home page

Creative Commons License Unless otherwise expressly stated, all original material on this page created by Diomidis Spinellis is licensed under a Creative Commons Attribution-Share Alike 3.0 Greece License.