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

imp-marcive

Session File

#!/bin/ksh

#######################################################
#
#  Shell script: imp-marcive
#
#  1999, Michael Doran, doran@uta.edu
#  University of Texas at Arlington
#
#  Runs the Voyager bulk import batch job against
#  the daily and monthly marcive files.
#
#  *** NOTE: Successful operation of this script
#      depends on /m1/voyager/xxxdb/sbin/Pbulkimport
#      being unbackgrounded!
#
#  see: /usr/local/scripts/marciver.pl
#
#  see: Voyager Technical Manual, p. 57
#
#######################################################


# Variables
 script_name=$0
 bull_path=/m1/incoming/marcive
 rpt_path=/m1/voyager/xxxdb/rpt
 log_file=log.imp.`date +%Y%m%d`.*
 del_file=delete.imp.`date +%Y%m%d`.*
 dis_file=discard.imp.`date +%Y%m%d`.*
 err_file=err.imp.`date +%Y%m%d`.*
 rep_file=replace.imp.`date +%Y%m%d`.*
 rej_file=reject.imp.`date +%Y%m%d`.*
 year=`date +%Y` 

 aquis_rcp=sappington@library.uta.edu
 sess_file=${bull_path}/sess-files/`basename ${script_name}`.log.`date +%d`
 to_sf=">> ${sess_file} 2>&1"

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

# Function to add comments to session file
add ()
{
    /usr/bin/echo "$1" >> ${sess_file}
}

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

# Check for receipt of files
if [ `ls -lF ${bull_path} | grep -v "/" | wc -l` -le 1 ]
then
    add " *** No marcive bulk import found to process this week. *** "
    add "\n     Possible /usr/local/scripts/marciver.pl ftp error."
    add "     Check /m1/incoming/marcive/marciver.log - mdd "
    swoosh "No-go: ${script_name}"
    exit 1
fi

# Give ownership of files to Voyager
/usr/bin/chown voyager:endeavor ${bull_path}/*

# Function to run the bulk import batch job
import ()
{

    if [ -x /m1/voyager/xxxdb/sbin/Pbulkimport ]
    then
	add "\nProcessing $1 \n"
        /m1/voyager/xxxdb/sbin/Pbulkimport \
          -f ${bull_path}/$1 \
          -i MARCIVE \
          -n
	# Pbulkimport should be unbackgrounded

        if [ -d ${bull_path}/${year} ]
        then
            /usr/bin/mv ${bull_path}/$1 ${bull_path}/${year}
        else
            /usr/bin/mkdir ${bull_path}/${year}
            /usr/bin/mv ${bull_path}/$1 ${bull_path}/${year}
        fi

        # send bulk import log file to acquisitions
	# ...add tail to session file
        # ...and then rename and move it
        if [ -f ${rpt_path}/${log_file} ]
        then
	    /usr/bin/echo "\n$1 processed by ${script_name} script." \
		>> ${rpt_path}/${log_file}
	    /usr/bin/tail ${rpt_path}/${log_file} | \
		mailx -s "Marcive load log" ${aquis_rcp}
	    add "\nTail from Bulkimport log file:\n"
	    /usr/bin/tail ${rpt_path}/${log_file} >> ${sess_file}
            /usr/bin/mv ${rpt_path}/${log_file} ${bull_path}/${year}/$1.log
	    add "Log file: ${bull_path}/${year}/$1.log"
        else
            add "\n *** ERROR: Missing Pbulkimport log file. *** \n"
        fi

	for afile in ${del_file} ${dis_file} ${rep_file} ${rej_file} ${err_file}
	do
	    if [ -s ${rpt_path}/${afile} ]
	    then
	      /usr/bin/mv ${rpt_path}/${afile} ${bull_path}/${year}/$1.${afile}
	    else
	      /usr/bin/rm ${rpt_path}/${afile}
	   fi
	done

    else
        add "ERROR: Pbulkimport program missing or not executable.\n"
        swoosh "ABORT: ${script_name}"
        exit 1
    fi

}

for file in `ls ${bull_path}`
do
    if [ -s ${bull_path}/${year}/${file} ]
    then
        /usr/bin/rm ${bull_path}/${file}
    elif [ -f ${bull_path}/${file} ]
    then
	case ${file} in
	UTA[DR]* )
	    import ${file}
	    ;;
	* )
            add "\n *** Non-marcive file in ${bull_path}: ${file}. *** \n"
	    ;;
	esac
    fi
done

 
# Send session file to operator...
add "\n${script_name} completed\n`date`"
swoosh "Marcive import done"

# and exit script
exit 0