Michael Doran Home Page
Contact | Site Map | Search  
  Home > Using Scripts > pulse-xfer
Using Scripts to Automate Voyager Tasks

pulse-xfer

#!/bin/sh

##########################################################################
#
#    Shell script: pulse-xfer
#
#    1999, Michael Doran, doran@uta.edu
#    University of Texas at Arlington Libraries
#
#    Transfers Web and ASCII PULSe files from Rocky to Bullwinkle.
#    Rocky is our PULSe interface to the Voyager database on Bullwinkle.
#    Should Rocky go down, we want to have the most current PULSe files
#    on Bullwinkle, so we can more easily switch over control.  Some of 
#    the files need to be modified to reflect being on a different host.
#      
##########################################################################

# Variables
 script_name=$0                          # Script name
 sess_file=/tmp/pulse-xfer.log           # Session file
 rcky_path=rocky:/opt/voyager/xxxdb      # Path to Voyager files on Rocky
 bull_path=/m1/voyager/xxxdb             # Path to Voyager files on Bullwinkle

# Test for remote copy ability
# create file
/usr/bin/echo "foobar" > /tmp/rcptestfile
# attempt to rcp it to Rocky
/usr/bin/rcp /tmp/rcptestfile rocky:/tmp/rcptestfile
if [ $? -ne 0 ]       # if it does not rcp successfully
then                  # send error message
    /usr/bin/echo "rcp error ${script_name}\n`date`" | mailx -s "rcp error" operator
    exit 1              # and exit script with error
fi

# Add file info and date to session file
/usr/bin/echo "Transfer of PULSe files from Rocky to Bullwinkle" > ${sess_file}
/usr/bin/echo "via ${script_name} on `date`" >> ${sess_file}

# Before transfer, backup bullwinkle's "redirect" webvoy.htm file
# (this is the html "index" page that redirects users to pulse, i.e. rocky)
if [ -f ${bull_path}/webvoyage/html/webvoy.htm ]
then
  /usr/bin/cp -p ${bull_path}/webvoyage/html/webvoy.htm \
                 ${bull_path}/webvoyage/html/webvoy.htm.redirect >> ${sess_file} 2>&1
fi

# Copy the Rocky ascii opac files to Bullwinkle
/usr/bin/rcp -pr ${rcky_path}/etc/ascopac ${bull_path}/etc >> ${sess_file} 2>&1
# Copy the Rocky WebPULSe files to Bullwinkle
/usr/bin/rcp -pr ${rcky_path}/etc/webvoyage ${bull_path}/etc >> ${sess_file} 2>&1
/usr/bin/rcp -pr ${rcky_path}/webvoyage/cgi-bin ${bull_path}/webvoyage >> ${sess_file} 2>&1
/usr/bin/rcp -pr ${rcky_path}/webvoyage/html ${bull_path}/webvoyage >> ${sess_file} 2>&1

# Make a copy of the "live" version of webvoy.htm that was transferred over from Rocky
/usr/bin/cp -p ${bull_path}/webvoyage/html/webvoy.htm \
               ${bull_path}/webvoyage/html/webvoy.htm.live
# and replace it with the "redirect" version saved earlier
/usr/bin/cp -p ${bull_path}/webvoyage/html/webvoy.htm.redirect \
               ${bull_path}/webvoyage/html/webvoy.htm

# For all the files that need path changes
for sed_file in ${bull_path}/webvoyage/cgi-bin/webvoyage.ini \
                ${bull_path}/webvoyage/cgi-bin/Pwebrecon.cgi \
                ${bull_path}/webvoyage/cgi-bin/scandoc.ini \
		${bull_path}/etc/webvoyage/local/opac.ini
do
    # if file exists
    if [ -s  ${sed_file} ]
    then
        # substitute Bullwinkle paths/URLs for Rocky 
	# paths/URLs, sending output to ".sed" file and 
        /usr/bin/sed -e 's/\/opt\/voyager/\/m1\/voyager/g' \
		     -e 's/pulse.uta/bullwinkle.uta/g' \
		${sed_file} > ${sed_file}.sed
        # then copy that version over the transferred file (preserves perms)
        /usr/bin/cp ${sed_file}.sed ${sed_file} >> ${sess_file} 2>&1
        # and remove the now unneeded dot-sed file
        /usr/bin/rm ${sed_file}.sed >> ${sess_file} 2>&1
   else
        /usr/bin/echo "No such file: ${sed_file}" >> ${sess_file} 2>&1
    fi
done

# Change ownership of all transferred files
for directory in /webvoyage/html /webvoyage/cgi-bin /etc/ascopac /etc/webvoyage
do
    /usr/bin/chown -R voyager:endeavor ${bull_path}${directory} >> ${sess_file} 2>&1
done

/usr/bin/echo "Script completed" >> ${sess_file} 2>&1
# Copy session file up to html sys files directory 
/usr/bin/rcp ${sess_file} rocky:/home/intranet/webroot/it-dept/sessfile/p-xfr-sess
# send copy to operator
/usr/bin/mailx -s "PULSe transfer" operator < ${sess_file}
# and exit script
exit 0