APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed
RSS Feeds RSS Feeds











(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Printer Friendly Version
->
-> Peek (user monitoring and control tool for character based apps)


Peek


There aren't many character based apps left, but if you still have one, you might like Peek




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.

cartoon

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.

Pseudo ttys take the form "/dev/pts001" (some OS's are different) and are normally assigned sequentially: the first person to ask for one gets 001, etc. This can cause problems with applications that expect that /dev/pts001 is always a wyse60 terminal, or will always be user "jane". Applications that work this way seldom have any real reason for doing so; it's usually just dumb programming that causes it, but sometimes you have to live with it.


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:

/etc/peek_replay /tmp/problem.log
 

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
 
cartoon

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.




If this page was useful to you, please help others find it:  





Comments?




More Articles by - Find me on Google+



Click here to add your comments
- no registration needed!


Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar

Kerio Samepage


Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

I am a Kerio reseller. Articles here related to Kerio products reflect my honest opinion, but I do have an obvious interest in selling those products also.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.

pavatar.jpg

This post tagged:

       - Administration
       - Terminals















My Troubleshooting E-Book will show you how to solve tough problems on Linux and Unix systems!


book graphic unix and linux troubleshooting guide



Buy Kerio from a dealer
who knows tech:
I sell and support

Kerio Connect Mail server, Control, Workspace and Operator licenses and subscription renewals



Click and enter your name and phone number to call me about Kerio® products right now (Flash required)