Change Process List sorting in GlancePlus

The process list in glance is sorted by CPU usage by default. You can also sort by process name and memory usage (RSS). To do this, from the process list screen hit “o”. You will be presented with a prompt:

Go to 1) Process; 2) Transaction; 3) Thread option screen(1) :

Select 1.

You’ll now be taken to a screen that looks like this:

                      INTERESTING PROCESS THRESHOLD OPTIONS

Display processes with resource usage:              Current Thresholds:

      CPU Utilization             >                 (0.0                %      )
      Disk I/O Rate               >                 (1.0                IOs/sec)
      Resident Set Size           >                 (20                 Mbytes )
      Virtual Set Size            >                 (500                Mbytes )
      User name                   =                 (all                       )
      Program name                =                 (all                       )
      TTY path name               =                 (all                       )
      Use match logic (and/or)    :                 (or                        )
      Sort key (name/cpu/rss)     :                 (cpu                       )

      Glance started or last reset: 08/18/2011  12:54:21
      Current refresh interval        : 5 seconds

Move the cursor down to the “sort key” field and type the name of key by which you want to sort. In parenthesis to the right is the current value. You’ll be prompted:

Set your user defaults to these values  (y/n/c)?

Press “y”.

 

http://deryaoktay.wordpress.com/2011/02/07/how-to-sort-processes-by-rss-memory-utilization-in-glance-in-hpux/

Advertisements

Display script output on screen and log it to a file at the same time

I’ve written plenty of scripts in the past where I’ve had to choose, do I want to script to output to stdout or do I want it to log to a file? Sure, if I’m outputting to stdout I could always call the script and pipe to tee to generate a log, but if I’m writing a script for others to use maybe I don’t want to have to depend on them to do that. Or maybe I just want to be lazy and not have to remember to pipe to tee every time I run the script.

Well, I just found the greatest trick that lets you do both from within the script.

#!/bin/bash

LOGFILE=${0##*/}.out
exec > >(tee ${LOGFILE})
exec 2>&1

( do stuff that generates output to stdout or stderr )

First, the ${0##*/} is some magic that works similarly to basename $0, but is way cooler looking. It works in bash, and I’ve read it works in ksh but I haven’t tested that.

Second is the exec > >(tee ${LOGFILE}) bit. I don’t know much about it, but apparently > >( ) is functionally similar to a pipe. It takes the script’s stdout and sends it to tee. Combine that with the exec 2>&1 and you’ve got both stderr and stdout getting piped to tee. Like I said, I don’t fully understand this technique, but it sure does work pretty well.

Thanks, Naked Ape!

Update – August 19, 2011 at 10:45:
I’ve been doing research on this. The ${0##*/} bit uses a shell feature called parameter expansion in bash or parameter substitution in ksh. According to the bash manpage:

${parameter##word}
The word is expanded to produce a pattern just as in pathname expansion. If the pattern matches the beginning of the value of parameter, then the result of the expansion is the expanded value of parameter with the longest matching pattern deleted. If parameter is @ or *, the pattern removal operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with @ or *, the pattern removal operation is applied to each member of the array in turn, and the expansion is the resultant list.

The exec > >(some_command) bit is called process substitution. It is supported in bash on machines that support /dev/fd or named pipes. It’s supported in ksh93 on machines that support /dev/fd.