Michael Doran Home Page
Contact | Site Map | Search  
  Home > Archives > Using Scripts > oclc-export
Using Scripts to Automate Voyager Tasks

oclc-export

Session File

#!/bin/ksh

#######################################################
#
#  Shell script: oclc-export
#
#  1999, Michael Doran, doran@uta.edu
#  University of Texas at Arlington Libraries
#
#  This program takes a list of Voyager bib record 
#  numbers for items recently cataloged by ACS 
#  (copy catloging, not originals) and using 
#  Pmarcexport, extracts the records from the 
#  database so that they can be exported to OCLC.
#
#  Program adds correct OCLC header to export file,
#  copies that file to Rocky, and then starts the
#  Perl script on Rocky that does the FTP.
#
#  See: rocky:/home/intranet/webroot/acs/oclc-input.html
#  See: rocky:/home/intranet/webroot/acs/cgi/oclc.incl.cgi
#  See: rocky:/home/intranet/webroot/acs/cgi/oclc.writ.cgi
#  See: rocky:/home/intranet/webroot/acs/cgi/oclc.dele.cgi
#       (these create input Voyager record #'s file)
#
#  See: rocky:/usr/local/scripts/oclc-xfer.pl
#       (transfers output file to OCLC server)
#
#  See: /usr/local/scripts/clean-rptdir
#       (removes log and output files > 60 days old)
#
#  See: Voyager Technical Manual, p. 51
#
#######################################################

# Variables
 bull_oclc_path=/m1/incoming/oclc
 bull_vygr_path=/m1/voyager/xxxdb
 rcky_inpf_path=/home/intranet/webroot/acs/cgi/db
 rcky_oclc_path=rocky:/opt/incoming/oclc
 date_sent=`date +%y%m%d`
 script_name=$0
 acs_rcpt=sappington@library.uta.edu

# Files
 sess_file=${bull_oclc_path}/oclc-xfer.sessfile	# Session file
 inpf_file=${rcky_inpf_path}/oclc.txt	    	# Marc export input file
  inpf_old=${rcky_inpf_path}/oclc.old		# Keep a copy of input
  inpf_new=${rcky_inpf_path}/oclc.empty		# Blank new file
 mexp_inpf=${bull_oclc_path}/oclc.txt		# Marc export input file
 arch_inpf=${bull_oclc_path}/oclc.`date +%m`    # Archive of input file
 mexp_prog=${bull_vygr_path}/sbin/Pmarcexport	# Marc export program
 mexp_outf=${bull_vygr_path}/rpt/marc.exp.`date +%Y%m%d`.*  # Data out file
 mexp_logf=${bull_vygr_path}/rpt/log.exp.`date +%Y%m%d`.*   # Error log
 xfer_file=${bull_oclc_path}/EDX.EBSB.IUA.FTP	# File to be FTP'd to OCLC
 
# for "operator" address(es) see /etc/mail/aliases
 
# Function to add comments to session file
add ()
{
    /usr/bin/echo "$1" >> ${sess_file} 2>&1
}

# Function to mail session file to operator
swoosh ()
{
    /usr/bin/mailx -s "$1" operator < ${sess_file}
}

# Clear out session file
/usr/bin/echo "Script: ${script_name}\n`date`\n" > ${sess_file}


#-------------------------------------------------------------------

# From, and on, Rocky: 

  # Retrieve input file of Voyager record numbers
  /usr/bin/rcp rocky:${inpf_file} ${mexp_inpf} >> ${sess_file} 2>&1
  if [ $? -ne 0 ]                          # if not successful
  then                                     # send error message
      add " *** ERROR: Unable to rcp ${inpf_file} from Rocky. *** "
      swoosh "ABORT: ${script_name}"
      exit 1                               # and exit script
  fi

  # Save a copy of input file on Rocky...
  /usr/bin/rsh rocky mv ${inpf_file} ${inpf_old} >> ${sess_file} 2>&1

  # And start over with an fresh (i.e. empty) file 
  /usr/bin/rsh rocky cp ${inpf_new} ${inpf_file} >> ${sess_file} 2>&1 

#-------------------------------------------------------------------

# Make an archive copy of input file
/usr/bin/cp -p ${mexp_inpf} ${arch_inpf} >> ${sess_file} 2>&1

# Check for presence of program and program input files
if [ -x ${mexp_prog} -a -f ${mexp_inpf} ]  # If they exist
then
    # Run the Pmarcexport program
    ${mexp_prog} \
	-rB \
	-mM \
	-t${mexp_inpf} >> ${sess_file} 2>&1
else  # send error notification
    add " *** ERROR: Missing ${mexp_prog}\n\t and/or ${mexp_inpf}. *** "
    swoosh "ABORT: ${script_name}"
    exit 1
fi


# Retrieve record count from session file and assign to variable
record_cnt=`/usr/bin/awk '/Records written/ { print $6 }' ${sess_file}`

# Test that record count is actually a number
/usr/bin/expr "${record_cnt}" + 1 > /dev/null 2>&1
# Exit status of "expr" should be 0 or 1 if valid
if [ ! $? -lt 2 ]  # If record_cnt not a number
then
    add " ${script_name} failed after Pmarcexport completed.\n"
    add " *** ERROR: record_cnt = ${record_cnt} ***  "
    swoosh "ABORT: ${script_name}"
    exit 1
fi

# Start new FTP file with proper header
/usr/bin/echo "<OCLCSYM: IUA;
 INSTNAME: The University of Texas at Arlington;
 DATESENT: ${date_sent};
 FORMAT: M;
 DATATYP: B;
 RECCNT: ${record_cnt};
 RUNOPT: P000090;>" > ${xfer_file}

# Append Pmarcexport output file to FTP file
/usr/bin/cat ${mexp_outf} >> ${xfer_file}

# Copy FTP file over to Rocky for FTPing to OCLC
/usr/bin/rcp ${xfer_file} ${rcky_oclc_path} >> ${sess_file} 2>&1
if [ $? -ne 0 ]                          # if not successful
then                                     # send error message
    add " *** ERROR: Unable to rcp ${xfer_file} to Rocky. *** "
    swoosh "ABORT: ${script_name}"
    exit 1                               # and exit script
fi

# Run FTP script on Rocky
/usr/bin/rsh rocky /usr/local/scripts/oclc-xfer.pl >> ${sess_file} 2>&1

add "Log file: ${mexp_logf}\n"
add "${script_name} completed \t `date`"
swoosh "OCLC export done"

# Send log file to Head of ACS
    /usr/bin/mailx -s "OCLC export done" ${acs_rcpt} < ${sess_file}

# exit script
exit 0