#!/usr/bin/bash
hn=$1
jn=$2
tfn=$3

mkdir -p /dev/shm/x$hn/${tfn}
cd /dev/shm/x$hn/${tfn}
tar -xf /beegfs/common_crawl/CC-MAIN-2019-35/pdfs/${tfn}.tar '*.pdf'
echo $(date) $hn $(pwd) untarred ${tfn}.tar for job $jn
ls *.pdf | sort --field-separator=_ -k1,1 -k2n,2 | cat -n |\
plinks.py $tfn || { echo $(date) $hn aborted job $jn for $tfn \[remember to clean up\] ; rm -f /dev/shm/stopJob ; exit 1 ; }
echo $(date) $hn tarring results from job $jn for $tfn in $(pwd)
tar -cf /beegfs/common_crawl/CC-MAIN-2019-35/pdfs/links/${tfn}.tar badpdfs_${tfn} links_${tfn}_*
rm *
cd ..
rmdir ${tfn}
echo $(date) $hn finished job ${jn} for ${tfn}
