#!/bin/ksh ## ## SCRIPT: who_on_anyhost_bygui ## ## Where: in $FEDIR/scripts where $FEDIR=/apps/nns_com/fea ## ############################################################################# ## PURPOSE: Shows the users logged into a specified SGI host machine, ## local or remote. Also shows the date-time of last bootup. ## ############################################################################# ## CALLED BY: 'hostconfig' script in $FEDIR/scripts ## ## actually, called by 'hostconfig.chestdef' in $FEDIR/scripts. ## ## (May eventually be called in a separate 'HostErrors' or ## 'HostActivityHistory' toolchest.) ############################################################################# ## MAINTENANCE HISTORY: ## Written by: Blaise Montandon 5dec2000 Based on 'sho_logins_anyhost_bygui' ## and 'whoison' scripts ## in $FEDIR/scripts ## Updated by: Blaise Montandon 19jan2001 Chg '/var/adm/utmp' to '/var/adm/wtmp*'. ## ## Updated by: Blaise Montandon 16apr2004 Chg default host from 'engvis00' to ## 'engfea00'. Use newer TkGUI script. ## Enhance some text in report. ## ## Updated by: Blaise Montandon 17apr2004 Add a user count. ############################################################################# if test "$FEDIR" = "" then FEDIR=/apps/nns_com/fea export FEDIR fi THISHOST=`hostname` #BIGCLIENT1="engvis00" BIGCLIENT1="engfea00" ########################################################################## ## PROMPT FOR HOSTNAME. ########################################################################## WINTITLE="Who is LoggedOn @AnyHost" export WINTITLE WIN_INFO="\ INPUT: Enter or select the name of an SGI host on the site network ... and click OK. (You can enter an IP address, if necessary.) ------ OUTPUT: ------ This utility shows users (and terminals) logged in to the specified host. The report includes information such as login-time, idle-time, and process-ID for each user-terminal. ------ USAGE: ------ The report identifies which user-terminals have not had activity for 24 hours, via 'old' in an 'IDLE TIME' column. (Perhaps a forgotten login session.) The report also quickly identifies which user-terminals have been active in the past minute, via a dot (.) in the 'IDLE TIME' column. --- The user-login data can be helpful when investigating problems on a SHARED machine, like $BIGCLIENT1. For REMOTE user-logins to the specified host, this utility shows the name of the host from which each user-login was performed. --- You can do queries on multiple hosts and bring the report windows side-by-side for comparison --- to check for normal/abnormal terminal connections. --- There are a few parameters of the 'who' utility, which is used to extract info for the report. If it were helpful, this GUI could be enhanced to provide the ability to quickly choose the more useful parameters via buttons and/or drop-down-option-lists." export WIN_INFO HOST_ID="$BIGCLIENT1" # HOST_ID="`hostname`" export HOST_ID # HOST_ID=`$FEDIR/tkGUIs/enter_hostid.tk` # HOST_ID=`$FEDIR/tkGUIs/enter_hostid_optmenu.tk` HOST_ID=`$FEDIR/tkGUIs/enter_hostid_optmenu_toghelp-scroll.tk` if test "$HOST_ID" = "" then exit fi ##################################################################### ## CHECK THAT THE HOST_ID EXISTS, if not THISHOST. ##################################################################### ## FOR TESTING: # set -x if test ! "$HOST_ID" = "$THISHOST" then HOSTCHECK=`rsh $HOST_ID cd 2>&1 | grep 'Unknown host'` if test ! "$HOSTCHECK" = "" then CONFIRM_TEXT="\ Specified Host: $HOST_ID is Unknown. " export CONFIRM_TEXT CONFIRM_GEOM="+080+080" CONFIRM_MINSIZE="350 150" CONFIRM_TITLE="$WINTITLE" export CONFIRM_TITLE CONFIRM_MINSIZE CONFIRM_GEOM CONFIRM_COLOR="#3DADFF" export CONFIRM_COLOR CONFIRM_FONT="-adobe-helvetica-bold-r-normal--*-100-*-*-p-*-*-*" export CONFIRM_FONT JUNK=`$FEDIR/tkGUIs/confirm.tk DISMISS` & exit ## continue fi fi ############################################################################## ## PREPARE OUTPUT/LIST FILENAME in $OUTLIST. ############################################################################## . $FEDIR/scripts/set_localoutlist ####################################################### ## PREPARE 'who' command. ####################################################### # TMP_FILE="/var/adm/utmp" TMP_FILE="/var/adm/wtmp*" WHO_CMD="who -T $TMP_FILE | sort -k1" ####################################################### ## PREPARE HEADING OF THE OUTPUT FILE. ####################################################### DATETIME=`date '+%Y %b %d %a %T%p %Z'` echo "\ ................... $DATETIME .......................... WHO is on HOST: $HOST_ID (sorted by userid) Column descriptions are at the bottom of this report. ------------------------------------------------------------------------------- IDLE TERM. TERMINAL START TIME TIME HOST OF REMOTE USER STATE NAME OF TERMINAL (hh:mm) PID LOGIN (if any) ------- -- ----------- ------------ ----- ---------- --------------- " > $OUTLIST ########################################################################## ## GENERATE REPORT CONTENTS. (from Local or Remote host) ########################################################################## # THISHOST=`hostname` ## This is set above. if test "$HOST_ID" = "$THISHOST" then ## FOR TESTING: # set -x WHO_OUT=`$WHO_CMD` echo "$WHO_OUT" >> $OUTLIST echo " ----------------------------- System boot time: " >> $OUTLIST who -b >> $OUTLIST ## FOR TESTING: # set - else ############################################ ## MAKE .rhosts FILE FOR THE USER, if needed. ############################################ . $FEDIR/scripts/mak_rhosts ## FOR TESTING: # set -x WHO_OUT=`rsh $HOST_ID $WHO_CMD` echo "$WHO_OUT" >> $OUTLIST echo " ----------------------------- System boot time: " >> $OUTLIST rsh $HOST_ID who -b >> $OUTLIST ## FOR TESTING: # set - ########################################################### ## REMOVE .rhosts FILE FOR THE USER. (Commented; not used.) ########################################################### # . $FEDIR/scripts/mv_rhosts fi ########################################################################## ## ADD REPORT 'TRAILER'. ########################################################################## USERS=`echo "$WHO_OUT" | awk '{print $1}' | uniq` USER_CNT=`echo "$USERS" | wc -l` USER_CNT=`echo $USER_CNT` USERS=`echo $USERS | fold -s -w70` ## FOR TESTING: # set -x if test $USER_CNT = 1 then USER_MSG="There is one user:" else USER_MSG="There are $USER_CNT different USERs:" fi ## FOR TESTING: # set - echo " ---------------------------- $USER_MSG $USERS ................... $DATETIME .......................... The list above was generated by the script $0 which was run from host $THISHOST. ------------- Commands used: $WHO_CMD and who -b on the specified host, $HOST_ID. ................................................................... DATA DESCRIPTIONS: ********* IDLE TIME: ********* The IDLE TIME column shows Hrs:Mins since Terminal Last-Active. . (dot) indicates there was activity on the line/terminal in the last minute, i.e. the terminal is 'current'. 'old' indicates at least 24 hours since activity on the indicated Terminal (device-line). *********** TERM. STATE: *********** The TERMINAL STATE describes whether someone else can write to that terminal --- and can indicate a bad line/terminal. If a bad line/terminal is encountered, a '?' is printed. A '+' appears if the terminal is writable by anyone. A '-' appears if it is not. 'root' can write to all lines having a '+' or a '-' in the STATE field. **** USER: **** In the USER column: . (dot) generally indicates a boot (init) process. *********** Data Source: *********** The data for this report was extracted from file(s) ${HOST_ID}:$TMP_FILE --- which contain(s) login-logout history of users and terminals since bootup. Reference: 'man who' ....................................................................... IMPLEMENTATION METHODS: This 'Who=is-logged-on' script can be accessed via a drawer in a command toolchest-utility, like 'Perf Tools' --- which is available as a drawer in the command/toolchest utility 'Handy Tools'. A site SGI toolchest-drawer path is SGI Toolchest -> Handy Tools -> Any Host - Perf Tools (Processes) -> Who is logged in @AnyHost Also available via SGI Toolchest -> nnsFEAmenu -> ABAQUS 6.4 Tools -> Any Host - PROCESSES QUERIES -> Who is logged in @AnyHost Or, you can implement the script (or the 'perftools' script or the 'handytools' script) as - a command alias, via your .profile file; examples: alias whohost='$0' alias ptools='$FEDIR/scripts/perftools' alias htools='$FEDIR/scripts/handytools' - a desktop icon, via the 'Find, File QuickFind' tool drawers; - a drawer in the SGI toolchest, via your .auxchestrc file. .......................... `date '+%Y %b %d %a %T%p %Z'` ................. " >> $OUTLIST ####################################################### ## SHOW THE OUTPUT FILE. ####################################################### #OLD:1995-1999# . $FEDIR/scripts/shofil_land $OUTLIST #OLD:summer99# $FEDIR/scripts/shofil_land_tk $OUTLIST $FEDIR/scripts/shofil $OUTLIST ## FOR TESTING: # set -