Listing 3. Script to set $TMPDIR Inside Batch Jobs

#!/bin/sh
#
# /etc/profile.d/tmpdir.sh
#
# If PBS_ENVIRONMENT exists and is "PBS_BATCH" or
#  "PBS_INTERACTIVE",
# set TMPDIR
if [ -n "$PBS_ENVIRONMENT" ]
then
  if [ "$PBS_ENVIRONMENT" = PBS_BATCH -o
       "$PBS_ENVIRONMENT" = PBS_INTERACTIVE ]
  then
    export TMPDIR=/tmp/pbstmp.$PBS_JOBID
  fi
fi