#! /bin/sh
 
#    May 16/13 - F.Majaess
 
#id  clntmpf - Used to cleanup old file(s) in /tmp on AIX.
 
#    AUTHOR  - F.Majaess

#hd  PURPOSE - "clntmpf" specialized script is used mainly to 
#hd            clean up old file(s) possibly left behind by 
#hd            the compiler upon failure in /tmp on AIX. 
 
#pr  PARAMETERS:
#pr
#pr    PRIMARY
#pr
#pr      target = file/subdiretory name identifier (='F8* and 'ipa*')
#pr      tarpath= subdirectory in which "target" data is residing 
#pr               and is accessible from current machine (=/tmp).
#pr      nmins  = number of minutes on which elimination of "target" is 
#pr               based (=90)
#pr      usr    = username code of "target" owner (=$USER)
 
#ex  EXAMPLE: 
#ex
#ex          clntmpf nmins=105 target='scratch*' 
#ex
 
 
#   * code used to set switches and deal with parameter=value arguments 
#   * as well as setting parameters to their primary/secondary defaults.
#   * The list of other arguments (if any) is returned in "prmtrl" var...
 
#  *  check if switches/parameters specified on script call
 
if [ $# -gt 0 ] ; then
  
#  * put argument list in "prmtrl" ...
   
  prmtrl=$@
# prmtrl=`echo $prmtrl | tr '[A-Z]' '[a-z]'`
  
#  * for each argument specified do...
    
  for prmtr in $prmtrl
  do
    case $prmtr in
 
#   * check for standard shell switches and set them accordingly
 
     --|-|[-+][aefhkntuvx]) set `echo $prmtr ` ;;
 
#   * case where a parameter is to be assigned a value
 
    *=*   ) eval $prmtr ;;
 
#   * anything else case skip...
 
    *  )  tprmtr="$tprmtr $prmtr";;
 
    esac
  done
  prmtrl=$tprmtr
  tprmtr=
 
fi
prmtrl=${prmtrl=}

#   * make sure arguments list variable "prmtrl" is initialized...
 
prmtrl=${prmtrl=}
  
#   * Skip extra parameters...
 
if [ -n "$prmtrl" ] ; then
 eval "echo '$0 : Skipped $prmtrl parameters !' "
fi
 
#   * code used to set hard coded primary defaults...
 
target=${target='F8+ipa'}
tarpath=${tarpath=/tmp}
nmins=${nmins=90}
usr=${usr=$USER}
 
#   * Make sure file/subdirectory to be transfered does not exist 
#   *                                                on front-end,
#   * otherwise, issue an abort message and exit.

if [ ! -d  "$tarpath/." ] ; then
#eval "0 clntmpf : not able to access $tarpath subdirectory !"
 exit 0
else
  :
fi
HOSTHW=${HOSTHW:=`uname -m`}
if [ "$target" = 'F8+ipa' ] ; then
 find ${tarpath}/. -user $usr \( -name 'ipa*' -o -name 'F8*' \) -type f -mmin +$nmins -exec \rm -f {} \; 2>>/dev/null || : 
else
 eval "find ${tarpath}/. -user $usr -name '$target' -type f -mmin +$nmins -exec \rm -f {} \; 2>>/dev/null || :"
fi
exit
