! 15 Feb 88
!
! unattend.cmd	- unattended send file to anything but DOS
!
! Written by Terry R. Lambert
!
!		  This script shows you how to program TERM to send a file to
!		  another computer so that all you have to do is watch, and
!		  that's only if you want to watch
!
! This script file assumes that you are using a modem (note the "hangup"), but
! will work over a direct-connect line if you use "NONE" for your phone number
! in the configuration file.  The "hangup" won't bother a direct-connect line.
!

! The following four variables are set to make this file easier to use
! and to understand.  These four lines are the only thing you should
! have to change to make it work with any computer or file
setvar config	"unixa"			! The configuration file to use
setvar prompt	"\$"			! The other system's prompt
setvar myfile	"/usr/term/bbs.txt"	! The file we want to send
setvar tofile	"/tmp"			! Where we are sending it to

connect $config				! call up the system and log in

flush					! throw away anything confusing
xmit "\r"				! hit a return to get a prompt
wait "$(prompt)"			! make sure that we get one

xmit "term -x\r"			! type "term -x" and hit return
wait "OK"				! wait until it runs

! send the file from me to it
xfer $myfile $tofile
! tell "term -x" to quit (next line can not have comment)
remote quit
wait "$(prompt)"			! (we should get a prompt when it does)

xmit "^D^D^D"				! log out
wait 1					! give it a second to make sure

hangup					! hangup the phone
quit					! and we're done

!============================================================================
Accompanying documentation:


Why "\$" instead of "$"?
	The dollar sign ($) character is special to TERM.  If you want a "real"
	dollar sign, you have to use a backslash (\) in front of it.  This
	is all in chapter 3 under "specifying strings".

What is "myfile"?
	We set 'myfile' to "/usr/term/bbs.txt" because we knew that when TERM
	has been installed, that's on file that's always there.  You could
	just as easily change it to "/bin/*.*" to send everthing in the "/bin"
	directory, or "*.*" to send everthing in the default directory (which
	ever one you happened to be in at the time).  If you ran a real estate
	office, and had a directory named "/listings", and it had files in it
	which contained listings of real estate for sale in in "Weber county"
	(in files that ended in ".wbr"), "Davis county" (in files that ended
	in ".dvs"), and "Morgan county" (in files that ended in ".mgn"), you
	could send all the "Davis county" listings to your office there by
	changing 'myfile' to "/listings/*.dvs".

What is "tofile"?
	The 'tofile' is a little tricky, because it can be either a directory
	or a filename, depending on the circumstances.  In this case, it is
	"/tmp", a directory that all UNIX/Xenix, and most other, systems have.
	The file, when it arrives, will be "/tmp/bbs.txt".  If we wanted to,
	since we are only sending one file, we could have given it any name we
	wanted it to have.  This is called 'explicitly' stating the file name
	and directory.  If we were sending more than one file, we would be
	REQUIRED to give a directory name on the other end, because we can only
	give one place for the files to go, and it has to be able to put every
	file we send there, and one filename can only hold one file.  With a
	directory name only, such as in our example, the file is given the same
	name on the other computer as it had on ours.  This is called
	'implicitly' stating the file name.

Why "connect $config" instead of "connect config"?
	This is why the dollar sign is special.  The 'connect' command takes
	as it's argument the name of a configuration file to connect to, in
	this case "unixa".   This means that, normally, you would use
	something like "connect unixa".  Notice that 'unixa' doesn't have
	quotes around it.  That's what the dollar sign does: it undoes quotes.
	Since 'config' is "unixa", saying "connect $config" is the same as if
	you were to say "connect $"unixa"", or, after the dollar sign is done,
	"connect unixa".  The name for this type of operation is 'Macro
	Substitution'.

What is "\r"?
	You already know that the dollar sign is special, and that you can
	still use it by putting a backslash (\) in front of it... well, this
	works for other special characters too.   "\r" is a way of saying the
	return key.  Other special characters are tab ("\t"), backspace ("\b"),
	escape ("\e"), "\\" for a "real" backslash, and so on.  Typing in
	special strings this way so that you can read them is called 'String
	Specification'.

Why "wait prompt" instead of "wait $prompt"?
	The 'wait' command takes a "quoted argument" (a string) to tell it
	what to wait for, so it doesn't need the quotes removed.  Waiting for
	a prompt after hitting return is a good way to tell that the computer
	on the other end is ready to be sent commands.  You "flush" before
	sending the return so that you can be sure that, if the computer on the
	other end sent you something with a dollar sign in it, you don't see
	it and mistake it for the prompt you want to wait for.

What does "xmit "term -x\r"" do?
	This runs TERM on the other machine so the it can receive the file we
	want to send it.  What it is really doing is typing "term -x" and then
	hitting return to make it run; this is exactly what you would type if
	you were running TERM on the other machine by hand.

Why wait for the "OK"?
	We wait for the "OK" so that we know that the TERM on the other end
	is ready for us to give it commands.  If we sent something before the
	"OK", it wouldn't get lost, but it probably would be ignored.

Is "xfer $myfile $tofile" that way because 'xfer' uses unquoted arguments like
connect does?
	Yes, that's exactly why.  The 'xfer' command is the way to tell TERM to
	send a file to the computer on the other end of the telephone.  If
	you'll remember what we set 'myfile' and 'tofile' to, you'll see that
	this 'xfer' command is really "xfer /usr/term/bbs.txt /tmp".

What is "remote quit"?
	Using "remote quit" is the same as if you were running TERM in "-x
	mode" on another computer and you typed control-C to get you back
	to a prompt.  You could 'xmit' a control-C ("xmit "^C""), but since
	you are in a script, you might as well use the more reliable method
	of sending it a 'quit' command.

Why do I want to "xmit "^D^D^D""?
	After waiting for (and getting) the prompt, you are done with what
	you wanted to do.  You could, of course, just hangup (explained below)
	the phone, and if the cable on the other end was wired right, that
	would log you out.  Since you can't be 100% sure that the cable on the
	other end is wired right, and that no one has changed the modem's
	switch settings, you should logout so that the next person to call
	does not get into your account.  The "wait 1" waits a second to be
	sure that you were logged out.

What does "hangup" do?
	"hangup" will force the modem to hangup the phone.  Some modems do
	not hangup the phone automatically when you logout; this makes sure
	that you don't get a phone bill for more time than you actually
	needed to use.

The "quit" command:
	The "quit" command causes TERM to quit running and go back to the
	program that it ran from, usually 'cron', 'sh', 'csh', or a menu
	system.  All script files that don't need to end up in terminal mode
	should include a "quit" command to clean up.
