#!/bin/ksh

WORKDIR=${PWD}

function create_remote_script {

echo "
   cd /home/a7users 
   for i in *  
   do  
       if [[ -d \$i ]]
       then
           if cd /home/a7users/\$i/.access7/comobj 2>/dev/null
           then
                for j in \$(find . -name '*.pab' -mtime +30)
                do
                  #  print -n \$j
                    name=\$(basename \$j .pab)
                    name=\$(print \$name | cut -c 5-)
                    print  "\$name"         
                done
           fi
        fi
   done
" > ${WORKDIR}/pa_remote_script
  chmod +x ${WORKDIR}/pa_remote_script

}


create_remote_script

if [ -f /tmp/pa.*.archive ]; then rm /tmp/pa.*.archive; fi
if [ -f /tmp/old_pa_sessions ]; then rm /tmp/old_pa_sessions; fi

for f in `list_processors -s`
do
   print $f
   rcp ${WORKDIR}/pa_remote_script $f:/tmp/wm
   remsh $f "cd /tmp/wm; chmod +x pa_remote_script; /tmp/wm/pa_remote_script" >> /tmp/old_pa_sessions
done

for name in `cat /tmp/old_pa_sessions`
do
    cd /home/a7users
    for i in *
    do
         if [[ -d $i ]]
         then 
             if cd /home/a7users/$i/.access7/comobj 2>/dev/null
             then
                 ll ????${name}.pa? ????${name}.*_pa?  >> /tmp/pa.$i.archive
             fi
          fi
    done 
done


