UNIX Hints & Hacks |
|||||||||||||||||||||||||||||||||||||
Chapter 7: Displays and Emulations |
|
||||||||||||||||||||||||||||||||||||
|
If you have ever needed to show someone a series of commands on two terminal devices or had to work on a remote system and display your activity to the administrator of that system, there is a way within UNIX to do this.
Flavor: AT&T, BSD
Shells: sh
Syntax:
sh -c "command | tee -a local_tty" 1>other_tty
The nice thing about the write command is that you can display a series of simple text messages to another terminal device. Unfortunately the key words are simple text messages . If you want to send commands and have the results sent to a terminal device, the write command will not work. You can achieve this through other means, however.
A new shell is created to execute a command and the output of the executed command is sent to the file descriptors of standard in. These file descriptors are actually pointing to the device that you want to share the results of the command with.
$ sh -c "date | tee -a /dev/ttyq0" 1>/dev/ttyd5
In this command, two devices are involved. The device /dev/ttyq0 is the terminal of the administrator running the command. The device /dev/ttyq1 is the terminal of the other administrator, operator, or user with whom the output is being shared.
A new shell (sh) is started and executes the date command ( -c). When date is run, the results are piped to tee which appends ( -a) the output to the end of device /dev/ttyq0. It then sends the STDOUT to the other terminal device, /dev/ttyq5.
This works well for individual commands but it can be time consuming if you have multiple commands that you have to execute. What you can do is, instead of passing a single command through, pass another shell through. This way, any commands you execute from that moment on are shared to the other terminal device.
$ sh -c "/bin/csh | tee -a /dev/ttyq0" 1>/dev/ttyd5
The shell can be any shell--csh, Bourne, Korn, or even tcsh. It doesn't matter. Try not to lose sight of the fact that after you run this command, you will have three shells open. When you exit the third shell that is being shared with another terminal device, the second shell closes as well. This leave you back with your original shell.
If you still don't want to type the entire command, it can be placed into a script for easy use. If you have a shared area on an NFS-mounted centralized file server, place this script there so you will be able to access it anywhere in your environment that your server has access to.
Flavors: AT&T, BSD
Shells: ALL
Syntax:
shtty program other_tty # vi shtty [ $# -lt 2 ] && echo "Usage: $0 program other_tty" && exit 2 MYTTY=`tty` PROG=$1 OTTY=$2 sh -c "$PROG | tee -a $MYTTY" 1>$OTTY 2>&1 0>$OTTY
Line 1: Verify that there is a program and a terminal device to share the output with. If not all the arguments are passed, display the proper syntax and exit.
Line 2: Set the terminal device variable ( MYTTY) to the current terminal device executing the script.
Line 3: Set the program variable ( PROG) to the name of the program that will be shared to the two devices.
Line 4: Set the variable ( OTTY) for the other terminal device that the program will be sharing to.
Line 5: Open a new shell, execute the program, and send it to the end of $MYTTY terminal device and out to the $OTTY other terminal device.
Before you use this in the real world, play with it first on your own terminal. All you have to do is open up two shells in different windows and make note of the terminal devices with the tty command. Run shtty and try various commands. The script has problems with terminal emulation routines that deal with cursor and screen manipulation on such commands as vi, more, and clear. The use of shtty doesn't reveal a hidden or encrypted password; therefore, if you need to show someone how to change a password on a system, this can be done safely.
Whether you want to walk someone through a series of tasks, provide insight into what you're doing visually, or convey the proper use of commands to another person, having the ability to display commands on another terminal device can be extremely beneficial and timesaving.
One of the most frustrating things for a support person is trying to walk a user through a series of commands when they insist on wanting to know what it takes to make something work in UNIX. This script is perfect for educating users in some UNIX basics. The best part is that you are still in control of the window. You can be on the phone with the user describing each step that you're doing and she can see the results.
If a user insists that a file exists when it doesn't, or she is unable to access files and directories when you know she can, you can have her use the script. Observe your user and see why she is having such problems. This is typical when users start using backslashes ( \), uppercase, and other characters that apply to DOS and not to UNIX. You will be able to pick out the problem right away and prevent the user from making the same mistake again.
The command also acts as a big brother, watching the steps of those who log in as root, or any other account for that matter. By placing the command into the appropriate startup file, such as .login, the command sends output to a predefined terminal device on your desktop. You can now spy on anyone who logs in with root access and watch what she is doing. It is best that you get management approval before attempting this little hack.
Man pages:
sh, tee, tty
World Wide Web:
TTY-Watcher--ftp://coast.cs.purdue.edu/pub/tools/unix/ttywatcher
UNIX Hints & Hacks |
|||||||||||||||||||||||||||||||||||||
Chapter 7: Displays and Emulations |
|
||||||||||||||||||||||||||||||||||||
|
© Copyright Macmillan USA. All rights reserved.