Peek, by Computronics, is a user monitoring/control tool for character based applications. Most Unix platforms are supported, including Linux and SCO OSR5.
Unlike some of its competitors, Peek doesn't modify the kernel; it instead relies upon the users running the "pksh" so that running /etc/peek can work. There's a couple of ways to do that; you can either just add a call to pksh to the end of their .profiles, or you can modify their login shell to use pksh- but not exactly as you might think: obviously you don't really want them running pksh, you want them running sh, or ksh, or csh, or maybe their shell isn't a shell at all but brings them straight into an application. Peek arranges for that by links to /usr/bin/pksh. The install creates symbolic links for pksh-csh, pksh-ksh and pksh-sh, but you can add any link you like, the trick being that your actual application is what follows the "-". When pksh runs, it looks at the name it was called with, and strips out what you really want by looking after the "-", and then it executes that. So if you have changed a user to use /usr/bin/pksh-ksh, they'll end up running ksh, but pksh will be in control.
Once that is true, you can use /etc/peek to view that users character screen. You can also "poke" commands through that will be executed by that users session. The control interface is very simple, has built in help, and none of it adds very much CPU overhead.
Computronics has done a thorough job of covering all the problems that come up from using this approach. You are not, for example, required to be running the same terminal type as monitored users, but if you are, you can specify that control code sequencs be executed rather than just shown as printable translations. Or, you can convert sequences into the appropriate sequences for the terminal you are using- of course this is slower, may not work at all for some sequences (just because your terminal may not support a capability the other terminal has) and is limited to just a handful of terminal types; still it is a useful feature.
The only problems I had at all with using the same terminal types was when I entered local peek commands. I had a session on tty04 that I monitored from tty03, and ran "scoadmin" on tty04. This displayed perfectly on tty03 (when using the "no translate" option which tells peek that your terminal types are the same), but if I triggered any local peek command, I could not recover the screen even with "Ctrl-L" (which is supposed to redraw it). However, once I used tty04 to do something which caused the screen to redraw, the peek on tty03 was once again perfect.
Another potential problem is the use of pseudo ttys. For any number of reasons, you may need to know (in scripts) what the "real" device is. The pksh makes that available in the variable _ttyname. You might also have a problem with the normal dynamic assignment of pseudo ttys, but Peek allows you to map specific ttys to specific pseudo ttys just by creating a the /etc/peek_pty_list file. That would contain lines like this:
/dev/ttya01 /dev/ptyp1 /dev/ttya02 /dev/ptyp2
This would force the assignment of specific pseudo ttys to specific terminals.
Peek also has a buffer which can be as large as 16K. That buffer lets you see what happened on the users screen before you ran /etc/peek. It's best feature, however, is when peek is used in combination with tee and the "peek_replay" command is then used to examine the captured file. Lets's pretend that the user on tty04 has called me with because they've just had a problem with their application. It's not something we can duplicate, but I need to see exactly what happened. Here's what I'd do:
Start peek using tee to save the output:
/etc/peek -nt | tee /tmp/problem.log Buffer Peek Program Peek_sco5, 1.09j2 (k) Copyright (c) 1999 Computronics. User? peekpassword User to monitor: tony Several users are logged in under that name: USER PID 1. tony 1144 /dev/tty04 2. tony 1181 /dev/tty05
After choosing the user, I'd immediately exit peek, and then run:
The peek_replay program recognizes an environment variable PEEK_BREAK (if you are using an ansi terminal you don't need to set it). This variable contains the characters you want peek_replay to pause at, normally anything that re-displays the screen. For ansi, it's set to "\e[H:\e1;1H", which are the "home cursor" sequences for ansi. This feature lets you replay the users screens step by step to see exactly what happened. As you can set up a background recording, this also is a great way to audit, especially since the "user" to monitor can be specified by tty device. Let's say, for example, that you don't completely trust your external support personnel (hardly an unusual situation, unfortunately). However, you need to let them dial in for regular maintenance and the like. You set things up so that their login will run pksh (or so that all logins do so). If you want, the file /etc/peek_devices can be created with only the modem lines you want to monitor, or you can leave that alone. Next , you set up a /etc/peek_on_me script (any name can be used) that contains
/etc/peek -u $_ttyname -comi > /tmp/peeklog &
And then finally in their .profile, add:
sh >/dev/null 2>&1 /etc/peek_on_me
When they log in, the /etc/peek_on_me script is started, and their session is recorded in /tmp/peeklog. You'd later use the peek_replay to run through the /tmp/peeklog and review exactly what they did (if you were monitoring multiple logins, you'd want to make /tmp/peeklog unique by adding on a user-name, timestamp or other identifier).
You can also use peek_replay in the immediate mode: a command like this is very useful:
/etc/peek -nt -u user -pipe | /etc/peek_replay
That runs you through the current buffer of the user, which would be ideal in the support scenario proposed above (-pipe wasn't mentioned in the manual I had, but the tech support folks pointed it out to me).
In addition to poking commands while actively monitoring a user, you can send commands from a script using the -cpl_poke option:
echo "lc" | /etc/peek -u mary -cpl_poke
If you needed to grab the results in a script, use the -pipe option as shown above.
Peek works by periodic polling, which means it could miss characters at high baud rates or when the user is telnetted in on a local lan. I observed no such problems in my testing, but it is possible to change the sample rate if this is an issue. Doing so will increase the CPU overhead of peek.
Got something to add? Send me email.
More Articles by Tony Lawrence © 2011-05-06 Tony Lawrence