joem@nos850.UUCP (Joe Muller) (02/12/91)
I am attempting to write a Korn Shell script for a cron that would automate the kermiting of files from a VAX/VMS system to an HP UX system. So far I have had very limited success; it can cu to our modem (/dev/ttyAp5), and after removing the LCK file, it echoes commands to the modem. So far I have been able to get it to successfuly dial out from a script, but what I have been having problems with is getting it to wait for a proper response before echoing the next command to the modem. I have tried cu'ing to the modem with this command: cu -l/dev/ttyAp5 -s2400 | tee -a log and then taking the response from the other machine as being the last line in the file 'log.' However, I am having difficulties in getting this to work correctly. What I would like to do is write an 'expect' command that would have the script wait for a proper response from a command echoed to the device. I could always just have the script sleep inbetween commands, but this assumes that the connection has already been made. If anybody has done something similiar to this, or can offer any advice or suggestions, please post them here.
spaf@cs.purdue.EDU (Gene Spafford) (02/13/91)
If you are using a recent version of ksh, I would suggest you try
something along the following lines:
1) dispatch the cu process as a co-process, ie:
cu -l/dev/ttyAp5 -s2400 |&
2) send it commands with "print -p"
3) Write an "expect" function along the lines of:
function expect
{
typeset pattern="$1"
while read -p response
do
if [[ $response = $pattern ]]
then
return
fi
done
}
3) Call "expect" with ksh style patterns, like
expect "*connected*"
The coprocess feature of the ksh is a very powerful way of handling
these kinds of situations, but many users don't seem to think to use
it.
--
Gene Spafford
NSF/Purdue/U of Florida Software Engineering Research Center,
Dept. of Computer Sciences, Purdue University, W. Lafayette IN 47907-2004
Internet: spaf@cs.purdue.edu phone: (317) 494-7825
les@chinet.chi.il.us (Leslie Mikesell) (02/14/91)
In article <228@nos850.UUCP> joem@nos850.UUCP (Joe Muller) writes: > > > I am attempting to write a Korn Shell script for a cron that would automate >the kermiting of files from a VAX/VMS system to an HP UX system. So far I >have had very limited success; it can cu to our modem (/dev/ttyAp5), and >after removing the LCK file, it echoes commands to the modem. So far I have >been able to get it to successfuly dial out from a script, but what I have been >having problems with is getting it to wait for a proper response before >echoing the next command to the modem. I have tried cu'ing to the modem with >this command: > cu -l/dev/ttyAp5 -s2400 | tee -a log > >and then taking the response from the other machine as being the last line in >the file 'log.' However, I am having difficulties in getting this to work >correctly. What I would like to do is write an 'expect' command that >would have the script wait for a proper response from a command echoed to >the device. I could always just have the script sleep inbetween commands, but >this assumes that the connection has already been made. If anybody has >done something similiar to this, or can offer any advice or suggestions, >please post them here. If you have a recent version of kermit, it should have a "script" command and be capable of initiating the connection all by itself without any help from cu. It can also do shell escapes from within its command mode so you can transfer a file in and then let a shell script parse the filename and generate your next action by writing a temp file of kermit commands which the top-level script executes via the "take" command. Oddly, there isn't a command line option to tell kermit to run non-interactively from a command file, so you have to redirect stdin for the main script which can just be a stack of "take" commands to do each operation. If it's just a straightforward file transfer the script can be pretty simple. I've been moving files between a unix box and an IBM running VM/CMS this way for several years, using a simple naming convention to decide what to do after the transfer. It's ugly but the price was right and it pretty much takes care of itself. Les Mikesell les@chinet.chi.il.us