#!/bin/bash
#PBS -S /bin/bash
#PBS -j oe
##PBS -W group_list=cstaff
#
# your normal script PBS directives above
#################################################


#################################################
# set up for repeatedly sending tail info to server
#  1. set outputFiles to list of files to do tail on
#  2. set tailInterval to #seconds between tail updates;
#     a tailInterval<120 may cause first "tail" to produce error message
#  3. each myNASsendTail command produces a different file to examine on phone;
#     only the result of the latest "tail" is shown for each myNASsendTail
trap 'if [ $(jobs -pr) ]; then kill $(jobs -pr); fi' SIGINT SIGTERM EXIT
outputFiles="tailTestSampleFile1 tailTestSampleFile2"
tailInterval=300
touch $outputFiles
myNASsendTail -d "Job in progress 1" -r $tailInterval $outputFiles &
myNASsendTail -d "Job in progress 2" -r $tailInterval $outputFiles &
##################################################



##################################################
# replace this section with normal script commands
#  - this should cause output to show up on $outputFiles
#
for file in *.out ;                              # replace
do                                               # all of
    ls -l $file >> tailTestSampleFile1           # these
    ls -f $file >> tailTestSampleFile2           # lines
    sleep 2 ;                                    # with
done                                             # mpiexec, etc.
#
##################################################



##################################################
# clean up backgrounded processes and do one last tail before leaving
if [ $(jobs -pr) ]
then
  kill $(jobs -pr)
fi
myNASsendTail -d "At job end" $outputFiles
##################################################
