#!/bin/ksh #This script takes the input name of a file of matched ckeys from #old serial solutions loaded records to those incoming in new file #and REMOVES these matched cases out of the catalogue via api transactions. # #The file of matched ckeys is obtained from findmatch.ksh program # #Step to put removed ckeys through touchkeys so that the records will be #de-indexed via the next adutext report run. This is unnecessary since #the api process for removing the ckeys puts the ckey into the touchkey #process already. #N. Lall, August 28, 2002 #Modified: Nov 24, 2003 to save records before removing them in case # they ever need to be restored. #Modified: Dec, 2003 to deal with standard file names each month #REMEMBER if the apitransaction process stops working, one could use #sirsi's delitem tool for the removals. IDENT=${0##*/} USAGE="$IDENT" if [[ $# -ne 0 ]] then echo "ERROR: $USAGE" exit 1 fi ####### System dependent. Change BRSConfig, UPATH and PATH accordingly. export BRSConfig=/s/sirsi/Unicorn/Config/brspath export UPATH=/s/sirsi/Unicorn/Config/upath PATH=$PATH:/s/sirsi/Unicorn/Bincustom:/s/sirsi/Unicorn/Search/Bin/:/s/sirsi/Unicorn/Bin:/usr/local/bin:/usr/bin; export PATH ###### DEBUG=YES temp=`getpathname rpttemp`/remss$$ workdir=/s/sirsi/Unicorn/Work/NDL/Serialsolutions INPUT=${workdir}/matchedckeys.sort INPUTfile=matchedckeys.sort today=`date +"%Y%m%d"` DONE="" PROBLEMS="" #Must ensure that the matchedckeys.sort file is recent enough or else #abort program run. Although any old file of matchedckeys.sort would #no longer match any records in the system to remove! cat $INPUT |\ selitem -iC -oB > ${temp}.itemids 2>${temp}.log if [[ -s ${temp}.itemids ]] then #Clean-up this file of itemids to get rid of final spaces and pipe: cat ${temp}.itemids | sed -e 's/ *\|$//g' > ${temp}.itemids2 2>/dev/null #Build the transaction to remove the item and record: cat ${temp}.itemids2 | awk -f${workdir}/transbuild.awk > ${temp}.apitrans.ndl fi #Should ensure that equal number of input ckeys to item ids arrived at #as expected. inputcnt=`cat $INPUT | wc -l | sed -e 's/^ *//g'` itemcnt=`cat ${temp}.itemids2 | wc -l | sed -e 's/^ *//g'` if [[ $inputcnt -eq $itemcnt ]] then #Create a backup of the records before removing them cat $INPUT |\ catalogdump -kf"035" -h -t"949" -of > ${workdir}/Backup/removedrecords.$today.bak.flat 2>/dev/null print "Proceeding with removal since number of input ckeys equals number of " >> ${temp}.log print "item keys ... Backup of records can be found at" >> ${temp}.log print "${workdir}/Backup/removedrecords.$today.bak.flat" >> ${temp}.log print "If you need to restore some or all of the records" >> ${temp}.log print "use restorerecords.ksh in same directory" >> ${temp}.log if [[ -s ${temp}.apitrans.ndl ]] then apiserver -h -e"${workdir}" <${temp}.apitrans.ndl 2>>${temp}.log > ${temp}.apitransout.ndl #Should remind user to see api error log here but not sure what #it's called yet! #do a check of the ckeys.deleted to ensure they really are gone! cat $INPUT |\ selcatalog -iC -oC 2>/dev/null > ${temp}oddleftovers if [[ -s ${temp}oddleftovers ]] then print "" >> ${temp}.log print "----------------------------------------------------------" >> ${temp}.log print "These titles (ckeys) were left behind by delitem because they had extra call number(s) with no copies." >> ${temp}.log print "Please remove manually:" >> ${temp}.log cat ${temp}oddleftovers >> ${temp}.log print "" >> ${temp}.log print "----------------------------------------------------------" >> ${temp}.log fi cat ${temp}.log | translate > ${workdir}/$INPUTfile.log 2>/dev/null print "Your log for this removal of records is found at: $INPUT.log" > ${temp}note print "Your list of removed CKEYS can be found at: $INPUT.bak" >> ${temp}note print "ANY records which errored out are in: ${workdir}" >> ${temp}note sirsiecho "" >> ${temp}note grep "^\^\@[0-9][0-9]*ZA" ${temp}.apitransout.ndl >> ${temp}problems DONE="YES" if [[ -s ${temp}problems ]] then print "PROBLEMS found in apitransout file, investigate:" >> ${temp}note cat ${temp}problems >> ${temp}note PROBLEMS="YES" else PROBLEMS="NO" fi sirsiecho "" >> ${temp}note cat ${workdir}/$INPUTfile.log >> ${temp}note #Move the matchedckeys.sort file to bak file since process is done mv $INPUT $INPUT.bak print "Moved the $INPUT file to $INPUT.bak" >> ${temp}note #Get the number of removals: deleted=`cat $INPUT.bak | wc -l | sed -e 's/^ *//g'` #REPORT out of all the SS stats for the serialsolutions webpage #https://www.ucalgary.ca/library/ITS/sirsi/serialsolutions.html print "" >> ${temp}note print "***UPDATE the serialsolutions.html webpage with stats:" >> ${temp}note cat ${workdir}/sstotalrecords |\ while read PT1 do total=$PT1 done print "Total number of MARC records in SS input file: $total" >> ${temp}note cat ${workdir}/ssloaded |\ while read PT1 do loaded=$PT1 done print "Total number loaded: $loaded" >> ${temp}note print "Total number deleted: $deleted" >> ${temp}note print " ...UNLESS there were any api errors!" >> ${temp}note totaluc=`cat ${workdir}/ALLckeys.sort | wc -l | sed -e 's/^ *//g'` print "Total in our database: $totaluc" >> ${temp}note print "" >> ${temp}note #Backup files with stats in them so not reused in error next month mv ${workdir}/sstotalrecords ${workdir}/sstotalrecords.bak mv ${workdir}/ssloaded ${workdir}/ssloaded.bak else print "No api transaction file found so did no removals!" >> ${temp}.log DONE="NO" fi fi if [[ $DEBUG = "NO" ]] then rm -f ${temp}* else sirsiecho "" >> ${temp}note print "REMEMBER that /tmp files remssPID are left behind." >> ${temp}note fi if [[ $DONE = "" ]] then print "Item ids did not match number of records!" > ${temp}shortnote elif [[ $DONE = "YES" && $PROBLEMS = "NO" ]] then print "$deleted records deleted without errors." > ${temp}shortnote elif [[ $DONE = "YES" && $PROBLEMS = "YES" ]] then print "Program ran but there are problem rpted in log" > ${temp}shortnote fi mail -s"Remove of OLD Serials Solutions DONE" -c"ndlall@ucalgary.ca" dkbrown@ucalgary.ca < ${temp}note #For production server do # mail -s"Remove of OLD SS Rpt" 2503547260@pcs.rogers.com < ${temp}shortnote #For test server do: mail -s"Remove of OLD SS Rpt" -c"ndlall@ucalgary.ca" dkbrown@ucalgary.ca < ${temp}shortnote exit 0