fir3net
PPS-Firenetbanner-780.5x190-30-03-17

FTP Transfer script for SGS logs files

Below is a script will send the latest log file of the SGS (Symantec Gateway) across to an FTP server. You would need to add this to your crontab to run every hour, in the event of multiple log files being generated per day.

#!/bin/sh
#
# This script will ftp gzip the latest sgs logfile and send it to your FTP server.
#

export PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/raptor/bin/ftp

SERVER=""
USER=""
PASSWD=""
LOG=`cd /var/log/sg/oldlogs/ ; ls logfile* | tail -n1`
LOGZIP=`hostname`_`date +%Y%m%d`.gz

find /var/log/sg/oldlogs/zipped_logs -name logfile\* -mtime +2 -exec rm -f {} \;
mkdir /var/log/sg/oldlogs/zipped_logs 2>/dev/null
gzip -c /var/log/sg/oldlogs/"${LOG}" > /var/log/sg/oldlogs/zipped_logs/"${LOGZIP}"

/usr/raptor/bin/ftp -n "${SERVER}" <<END_SCRIPT
quote USER "${USER}"
quote PASS "${PASSWD}"
lcd /var/log/sg/oldlogs/zipped_logs
put "${LOGZIP}"
quit
END_SCRIPT
RC=$?

if [ "${RC}" = 0 ]
then
    logger -t FTP_LOG_TRANSFER -p daemon.info "Successfully sent "${LOGZIP}" to "${SERVER}""
    exit 0
else
    logger -t FTP_LOG_TRANSFER -p daemon.err "Unsuccessfully sent "${LOGZIP}" to "${SERVER}"" 
    exit 1
fi

About the Author

RDonato

R Donato

Rick Donato is the Founder and Chief Editor of Fir3net.com. He currently works as a Principal Network Security Engineer and has a keen interest in automation and the cloud.

You can find Rick on Twitter @f3lix001