Newsgroups: comp.parallel.pvm
From: bubeck@peanuts.informatik.uni-tuebingen.de (Till Bubeck)
Subject: Re: Removing /tmp/pvm* files..
Organization: Technische Informatik, Uni Tuebingen
Date: 25 Jan 1995 19:59:00 GMT
Message-ID: <3g6ai4$cfd@wsiserv.informatik.uni-tuebingen.de>

Park Jong Hoon (pjh@emerald.yonsei.ac.kr) wrote:
: I have a question. After pvm is halted, we must remove pvm* (for example, pvm01324) in /tmp directory. Does anyone have good solution?

: Please answer my question...

: E-mail : pjh@emerald.yonsei.ac.kr

A long time ago, I caught the following shell scripts from
news. I now repost them to increase the number of users.

Till
--
                ,,,
               (o o)
-----------oOO--(_)--OOo-------------------------------------------
|  Tilmann Bubeck            |   _||__                            |
|  Universitaet Tuebingen    |  /   . | <- Berlin                 |
|  Technische Informatik     |  |    _/                           |
|  Sand 13, 72076 Tuebingen  |  |_   \                            |
|  Germany                   |   /*__/ <- University of T"ubingen |
|------------------------------------------------------------------
|  Tel: +49 7071 295865     Fax: +49 7071 610399                  |
|  Email: bubeck@peanuts.informatik.uni-tuebingen.de              |
|  WWW/Mosaic: http://www-ti.informatik.uni-tuebingen.de/~bubeck  |
-------------------------------------------------------------------

#!/bin/csh -f
##############################################################################
# FILE:  pvmcleanup
# DESCRIPTION:  
#   Used to cleanup hopelessly lost PVM daemons and user processes within
#   a cluster of RS6000s. Also removes the files in /tmp that some PVM 
#   versions leave behind.  
#
#   Usage:  pvmcleanup  <hostfilename> < -u option> <u args>
#
#   Argument 1: hostfilename 
#     Required.  Contains the name of machines where pvmcleanup should do 
#     its work.  Generally, this is your PVM hostsfile, but it can be any file
#     which contains one machine name per line.  The full path name should be 
#     specified if the file is not in the current directory.  Valid hostnames 
#     are assumed to be lines that begin with a-z, A-Z.  Lines that begin 
#     with other characters will be ignored.  All "extra" characters on a 
#     valid hostname line will be ignored (only the hostname is extracted).
#   Argument 2: -u  
#     Optional.  No other options are valid at this time.  This option tells 
#     pvmcleanup to kill other user processes in addition to PVM daemons.  
#     Only daemons will be killed by default.  If the -u option is used, the 
#     names of user processes should follow it on the command line.  If -u
#     is used without u args, then it is ignored and only PVM daemons will
#     be killed.
#   Arguments 3 - N: u args 
#     These are the names of user processes which should be killed.  Care 
#     should be taken with specifying the u args since any process with a 
#     name that contains the search string will be killed.  For example, if 
#     the command:
#   	pvmcleanup myhostfile -u junk
#     is issued, then all of the following processes would be killed:
# 	junk  junk1 junkproc  anyjunk   somejunkhere  /tmp/junk
#
#   After parsing the command line, pvmcleanup will rsh to each host and call 
#   the second part, pvm_rshcleanup, locally on each host to do the actual 
#   cleanup work.
#
#   Location of the pvm_rshcleanup script is defined by the localbin variable
#   in the first line of the script below.  This MUST be modified if it is
#   installed somewhere else.
#
#   Designed to be used only in an RS6000 cluster where user home directories
#   are under AFS.
# AUTHOR:  Blaise Barney	(bbarney@tc.cornell.edu)
# LAST REVISED:  7/12/93
##############################################################################

set localbin="/usr/local/pvm/contrib/pvm_cleanup"

##### Step 1. Make sure user has supplied name of pvm hostfile
if ($#argv == 0) then
   echo '  usage:  pvmcleanup <hostfile-name> < -u > < u args >'
   echo '  You need to supply the name of your PVM hostfile.  Try again.'
   exit(0)
endif

##### Step 2. Check for existence of PVM hostfile
set hostfile=$argv[1]
if (! -e $hostfile) then
   echo "  Can not find the PVM hostfile: $hostfile"
   echo '  Check for misspelling or complete pathname and try again.'
   exit(0)
else
   echo "pvmcleanup will use your PVM hostfile: $hostfile"
endif

##### Step 3. Determine if the -u option is being used and process accordingly
if ($#argv >= 2) then
  if ($argv[2] != "-u") then
    echo '  usage:  pvmcleanup <hostfile-name> < -u > < u args >'
    echo '  Command line incorrect.  Try again.'
    exit(0)
  else if ($argv[2] == "-u") then
    if ($#argv < 3) then
      echo '  usage:  pvmcleanup <hostfile-name> < -u > < u args >'
      echo '  -u option used without arguments...ignored'
      echo '  Continuing anyway...'
    else
      if ( -e $HOME/PvmProcsToKill ) then
         rm $HOME/PvmProcsToKill
      endif
      foreach c_arg ($argv[3-$#argv])
         echo $c_arg >> $HOME/PvmProcsToKill
      end
    endif
  endif
endif

##### Step 4. Extract host names from the pvm hostfile 
set pvmhosts=`cat $hostfile | egrep "^[a-z,A-Z]" | cut -f1 -d" "`
foreach thishost ($pvmhosts[*])
   echo "   Cleaning up on host: $thishost"
   rsh $thishost $localbin/pvm_rshcleanup 
end

##### Step 5. Cleanup the file created to hold options
if ( -e $HOME/PvmProcsToKill ) then
  rm $HOME/PvmProcsToKill
endif

echo 'Done.'




#!/bin/csh -f
##############################################################################
# FILE:  pvm_rshcleanup
# DESCRIPTION: Called by pvmcleanup.  Will remove pvm files left in /tmp
#   and kill whatever pvmd processes it can find.  If user specified the
#   -u option with call to pvmcleanup, then the user processes will
#   be killed.  See pvmcleanup also. Designed to be used only in an RS6000 
#   cluster where user home directories are under AFS.
# AUTHOR:  Blaise Barney 	(bbarney@tc.cornell.edu)
# LAST REVISED:  6/22/93
# CHANGES: 
#   . changed to work on a cluster of SUN4 machines 
#                1/31/94        (bubeck@peanuts.informatik.uni-tuebingen.de)
##############################################################################

##### Step 1.  Kill any process which smells like a pvm daemon
set pvmdpids=`ps uxw|grep pvmd|grep -v grep|grep -v cleanup|cut -c9-16`
foreach killpid ($pvmdpids[*])
  kill -9 $killpid
  echo "      Killed pvmd process $killpid"
  end

##### Step 2.  Kill any additional processes specified by user
if ( -e $HOME/PvmProcsToKill) then
  set pvmprocs=`cat $HOME/PvmProcsToKill`
  foreach pvmproc ($pvmprocs[*])
    set pvmdpids=`ps uxw|grep -v grep|grep $pvmproc|grep -v cleanup|cut -c9-16`
    foreach killpid ($pvmdpids[*])
      kill -9 $killpid
      echo "      Killed user process: $pvmproc $killpid"
      end
    end
endif

##### Step 3.  Get rid of the pvm?.uid files in /tmp
set myuid=`id | cut -d "(" -f1 | cut -d "=" -f 2`
if ( (-e /tmp/pvmd.$myuid) || \
     (-e /tmp/pvml.$myuid) || \
     (-e /tmp/pvmu.$myuid)) then
  echo "      Removing `ls /tmp/pvm?.$myuid`"
  rm /tmp/pvm?.$myuid
endif

set myuname=`whoami`
if (-e /tmp/pvmd.$myuname) then
  echo "      Removing `ls /tmp/pvmd.$myuname`"
  rm /tmp/pvmd.$myuname
endif


