Print on Nyquist Easily from CEB 531
by Ryan Northcott
of the Spinning LED Clock Group
Posted 26 Mar 2001
To start off, I would like to appologize to everyone who would have found this script useful several reports ago! It has been quite a technical challenge for me to write this script. I hope that it is useful to many people not only in EE 552, but in all courses that use the CEB 531 lab. Perhaps it will also serve as a bit of a tutorial for PERL script as well! I tried to put some comments into the code to make it understandable. Please take a look! And now for an explanation of what this script does...
If your university experience has been anything like mine, you have learned to despise, with great feeling, the printer in CEB 531. In my humble opinion, this printer is possessed by THE DEVIL!!! Not only does it not function properly the majority of the time, but it also charges you 10 cents per page. What a rip off! Many of us are required to use software in the 531 lab but printing is always a hassel. When the 531 printer starts charging you to spit out blank pages instead of the files that you requested, most people try to print elsewhere. However, this involves the often tedious process of copying the files over to your Nyquist account using FTP or some other program. Then you must Telnet into nyquist and spool the files to the printer using the lpr command. This can be quite a pain.
How would you like it if you could do all of this by typing one command from the terminal window? Wouldn't that be fantastic! I've dreamed about this myself for months! Finally, I have found a solution. I have spent upwards of 24 hours researching information on PERL script and writing a simple program that would do just this very thing. Now, I offer it to you so that all may reap the benefits of 5 cent printing on printers that actually work properly!
Here's what you must do to install it:
- Copy the file pon.pl to your root directory in the 531 lab.
- Make the file pon.pl executable by typing the command:
chmod 700 pon.pl
- Create a subdirectory in your root directory called 'PrintFiles' by typing the command:
mkdir PrintFiles
Make sure to get the capitalization correct!
- Telnet over to your Nyquist account and create a subdirectory by the same name in your root directory by typing:
mkdir PrintFiles
Once again, mind the capitalization.
- Log out of your Nyquist account.
Here's how to use the script:
- When printing from any program in the 531 lab, make sure that the "Print To File" option is selected in either the "Print" or "Print Setup" dialog box. Type in the path to the 'PrintFiles' directory in the filename box as: ~/PrintFiles/
- From your root directory in the 531 lab, type:
pon.pl
That is short for "Print on Nyquist".
- The script will ask you to select a Nyquist printer to print to from a list of available printers. Type the number of the printer that you wich to print on and press return.
- The script will then ask you to enter you login name and password for your nyquist account. Type these in. Your password will not be echoed to the screen to protect your privacy.
- The script will then ask you for your password again. I wanted to avoid this problem but I have not been able to find a way around it. This is due to the fact that the FTP program does not read the password from standard input but uses some kind of terminal emulation technique to get your password from you. If anyone knows how to get around this, please let me know. But for the mean time, we'll just have to deal with typing the password twice.
- The script will then log into your nyquist account using FTP and copy all of the .ps files in your local 'PrintFiles' directory to your nyquist 'PrintFiles' directory.
- After ending the FTP session, the script will then log into you nyquist account using Telnet. Once the connection is established, it will spool all of the .ps files to the printer that you selected, and then delete them.
- After ending the Telnet session, the script will ask you if you would like to delete the postscript files from your local directory. Type "y" to delete them all or "n" to save them for later. If you do not delete them, they will be printed again the next time you run the script.
Notes for the technically astute:
- Kees is slowly trying to block access to the EE file servers from unsecure programs like FTP and Telnet. Eventually, SSH and SCP will be the only way to access them. These programs are similar in functionality to FTP and Telnet but they use encryption. The script will need to be tweaked to support SSH and SCP in the future. By the time this is necessary, however, we may be in the new building and this script may no longer be needed! I tried to write this script to use SSH and SCP but the EE servers don't support SSH v1.0 anymore which is the version installed in the 531 lab right now. I downloaded version 2.4.0 and tried to compile and install it, but it was too large to fit in my directory. For this reason, you should wait until CNS gets around to installing the newer version on the application server.
- This script was tricky to write for several reasons.
- I had not had any previous experience with PERL.
- I had never played around with UNIX process control commands like i/o pipes.
- Telnet and FTP both behave differently when running as forked processes.
The third point was probably the biggest challenge. I needed to find ways to capture the input and output streams of both programs so that my script could interact with them. Telnet was not too difficult to control but FTP was a beast! It uses some kind of terminal emmulation which is separate from the normal standard i/o. You'll notice if you look at the contents of the script file, that FTP is launched with the -k option turned on. This makes it behave somewhat normally. Without this option, it is totally uncontrollable! The password line still remains a mystery to me. I assume that the author of the program did not know how to turn the local echo off properly so instead he did some kind of event capture to pull the key strokes directly from the computer's event queue.
- If this script breaks sometime in the near future, it may be because the number of lines in the welcome text has changed (this is the text displayed when you login to nyquist using FTP or Telnet). I needed to determine when it was time to send the username and password to the remote host. Since the username and password prompts are not terminated with an end-of-line character, they are not passed through the pipe to the script. So I designed the script to detect when the line preceeding each prompt had been sent and then perform the appropriate action. If the script breaks, log in using FTP and Telnet and count the number of lines preceeding each prompt. Then update these magic numbers in the script file.
- The 'lp' command must be used instead of the 'lpr' command to spool the files. Also, this command must be issued on the Poisson
server because it is not recognized on nyquist. Perhaps I should have named the script 'pee.pl' for print on EE!<\li>
For more info on writing PERL scripts, visit, www.perl.com.
by Ryan Northcott
of the Spinning LED Clock Group
Posted 26 Mar 2001