corz.org text viewer..
[currently viewing: /public/linux/usr/local/bin/corz-grablogs.sh - raw]
#!/bin/bash
# last updated Friday May 17, 2013
#
# grab logs
#
# download the site logs my home mirror for extended examination..
#

# get host name..
if [ -z $1 ]; then
    echo
    echo "Please supply a domain name on the command-line. e.g.."
    echo
    echo "$0 foobar.net"
    echo
    echo "grabcomments will then use settings file: ~/.sftp/foobar.net"
    echo
    exit 1
fi

# grab settings..
. ~/.sftp/$1

echo "Archiving logs for $host.."

newname=$now.$host.logs.tar.gz

if [ ! -e $logstore ]; then
    mkdir -pv $logstore  > /dev/null
fi

echo "Zipping logs.."
cd $home/$logdir
cd ..

tar cfz $newname log >> $logfile
rm -rf $home/$logdir/$logarc/.* &> /dev/null
rm -rf $home/$logdir/$logarc/phperr.* &> /dev/null

mv $newname $logstore/

remount  > /dev/null
if [ ! -d $ol_logs ]; then
    mkdir -pv $ol_logs  > /dev/null
fi
if [ -e "$ol_logs" ];then
    echo -n "Copying log backup to offline storage facility.. "
    cp  $logstore/$newname $ol_logs/
    if [ -e "$ol_logs/$newname" ];then
        echo "Success!"
        rm $logstore/$newname >> $logfile &> /dev/null
        rmdir $logstore &> /dev/null
    else
        echo "Fail!"
        echo "Could not copy $logstore/$newname to $ol_logs"
    fi
    echo
fi
rmdir $arcroot/$host &> /dev/null
rmdir $arcroot &> /dev/null


echo "Performing sftp operations for $user@$host.."

sftp -b "/usr/local/bin/$host/grablogs" $user@$host
rc=$?
if [ $rc != 0 ] ; then
    echo "**WARNING** grablogs sftp for $host returned an error: $rc"
     echo "**WARNING** grablogs sftp for $host returned an error: $rc"|mailx -s "Error in up grablogs sftp!" postmaster
    exit $rc
fi

echo "Setting local file permissions.."
chmod 777 $home/inc/log/**/r />
now=`date "+%Y.%m.%d-%H.%M"`

command -v fortune >/dev/null 2>&1 || { echo "Smile! It's real-time!"; exit 0; }
fortune
echo "grablogs for $host complete at $now"

exit 0

Welcome to corz.org!

I'm always messing around with the back-end.. See a bug? Wait a minute and try again. Still see a bug? Mail Me!